【发布时间】:2011-08-26 20:54:57
【问题描述】:
我正在尝试构建一个包含每个表单元素的所有值的数组。刚刚发现警报有效,但在 console.log 上数据为空,我是否无法理解 javascript 中的作用域是如何工作的?
var data = new Array();
$("#page2 input").each(function(index) {
alert($(this).attr('id'));
data[$(this).attr('id')] = $(this).val();
});
非常感谢您的宝贵时间,
【问题讨论】:
-
编写效率更高:
this.id和this.value。
标签: javascript jquery foreach scope each