var conversations = new Array();
jQuery('.CChatWindow').each(function(){
if (jQuery(this).is(":visible") && jQuery(this).attr("data-conversationid") != 0) {
alert(jQuery(this).attr("data-conversationid")); // returns 1 and 2
conversations.push = (jQuery(this).attr("data-conversationid"));
}
});
alert(conversations); // returns an empty string
我的代码有什么问题? array.push 似乎不起作用。 谢谢!
最佳答案
改变
conversations.push = (jQuery(this).attr("data-conversationid"));
到
conversations.push( jQuery(this).attr("data-conversationid") );
Array.push()
是函数调用而不是赋值。
关于javascript - Javascript 中的 array.push 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10700989/