使用jQuery,我通过某个进程更改了输入文本字段的值。完成该过程后,我需要捕获此更改并将其应用于另一个进程。我的问题是,我似乎无法捕捉到这个变化并将其分配给一个变量。我知道这些更改正在发生,因为DOM正在更新。此外,这个变量赋值在IE中可用,但不适用于我测试过的其他浏览器。jQuery - DOM操作的结果不能分配给变量?
下面是一个片段来证明我的观点(你可以在这里看到这个在线:http://jsfiddle.net/xMwAE/)。
<form>
<input type="hidden" name="my_hidden" value="Hidden Field" />
<input type="text" name="my_text" value="Text Field" />
</form>
$().ready(function() {
$('input[name=my_hidden]').val('Hello Hidden Field');
$('input[name=my_text]').val('Hello Text Field');
// Display
var temp = $('form').html();
// Though the DOM is updated with the new values. The variable temp
// does not capture the changes to the input text field, but captures
// the change in the hidden field. When in IE, temp captures the
// changes in both fields.
alert(temp);
});
显然,我需要跨浏览器的一致行为。任何想法发生了什么?
你是一个天才!似乎工作,现在已经挣扎了好几天。所以我必须使用setAttribute酷!非常感谢!啤酒?大声笑 – Aman 2010-11-12 16:06:30
啤酒听起来不错^^ – 2010-11-13 14:51:10