This problem is a little bizarre and I'm curious if anyone has any idea what's going on. You can get the CSS,HTMl and JS here, but the behavior I see on my local machine isn't the same as in the fiddle. The intent is was that a user will click on a span tag inside of a div and and a modal will pop up (which I haven't gotten to yet) and the user will be able to edit and save changes. You can see in the update function a text box is appended to the #hidden
element. Although I never set the value of the text box, when a span tag is clicked a text box is appended to the element with (almost) the entire value of the view state hidden ASP.net field. I changed the id of the hidden element to garbage thinking maybe hidden was a bad ID to use, but I still got the same effect. Does anyone have idea what's going on?
这个问题有点奇怪,我很好奇是否有人知道发生了什么。你可以在这里获得CSS,HTMl和JS,但是我在本地机器上看到的行为与小提琴中的行为不同。目的是用户将点击div内的span标签,并弹出一个模态(我还没有得到),用户将能够编辑和保存更改。您可以在更新功能中看到一个文本框附加到#hidden元素。虽然我从未设置文本框的值,但是当单击span标记时,文本框会附加到元素上(几乎)视图状态隐藏的ASP.net字段的整个值。我将隐藏元素的id更改为垃圾思想,可能隐藏的是一个坏ID,但我仍然有同样的效果。有谁知道发生了什么?
EDIT: the '#hidden' element is the same thing as '#asdf' full code:
编辑:'#hidden'元素与'#asdf'完整代码相同:
<script type="text/javascript">
$(document).ready(function () {
var personArray = [{
name: 'firstName',
gender: 'male',
age: 30
}, {
name: 'secondName',
gender: 'female',
age: 20
}];
//finds over object in the array and every property on that object
//and makes a control out of it and styles is.
function pretty(array) {
var divArray = [];
for (var i = 0; i < array.length; i++) {
var $div = $('<div>').addClass('person');
for (var prop in array[i]) {
var $span = $('<span>').text(prop + ': ' + array[i][prop]);
$div.append($span);
}
divArray.push($div);
}
return divArray;
}
$('body').append(pretty(personArray));
$('.person span').click(function () {
update($(this).parent());
});
function update(control) {
var $spans = $(control).children('span');
for (var i = 0; i < $spans.length; i++) {
$('#asdf').append($spans[i]).css('float', 'left');
var textBox = $('input').attr('type', 'textbox').css('float', 'right');
$('#asdf').append(textBox);
}
$('.updatePanel').fadeIn();
}
console.log('wEPDwUKLTIwNjAyODU4M2RkOhAAaDmHX8rBCXDQytiqIx94ch'.length);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="asdf" style="float:right" class="updatePanel"></div>
</div>
</form>
</body>
1 个解决方案
#1
2
On this line
在这条线上
var textBox = $('input').attr('type', 'textbox').css('float', 'right');
You probably want to do:
你可能想做:
var textBox = $('<input>').attr('type', 'textbox').css('float', 'right');
ViewState is stored in a hidden input element, and doing $("input") will select all input elements on the page. The ViewState element is probably the first one on the page.
ViewState存储在隐藏的输入元素中,执行$(“input”)将选择页面上的所有输入元素。 ViewState元素可能是页面上的第一个元素。
#1
2
On this line
在这条线上
var textBox = $('input').attr('type', 'textbox').css('float', 'right');
You probably want to do:
你可能想做:
var textBox = $('<input>').attr('type', 'textbox').css('float', 'right');
ViewState is stored in a hidden input element, and doing $("input") will select all input elements on the page. The ViewState element is probably the first one on the page.
ViewState存储在隐藏的输入元素中,执行$(“input”)将选择页面上的所有输入元素。 ViewState元素可能是页面上的第一个元素。