2012-03-02 77 views
0

我正在尝试将一个元素的id添加到数组中。但我收到错误 - Microsoft JScript运行时错误:对象不支持此属性或方法。 下图显示了我如何将ID值添加到数组。为什么$(this).id的值未定义?将此this添加到JS数组中

enter image description here

感谢

+0

请发布您的HTML – 2012-03-02 06:21:00

回答

4

你应该做的事:

 

var comments = []; 
//instead of 
var comments = {}; 
 

因此,这将是:

 

var comments = []; 
$("textarea.comment_wide_textbox_control").each(function() { 
    comments.push($(this).attr("id"), $(this).val()); 
}); 

0

我会尝试$(this).attr('id');

+0

'this.id'工作得很好。没有必要使用jQuery,它不增加任何价值,也不会解决问题。 – jfriend00 2012-03-02 06:42:44