每次用Javascript调用函数时,我都试图向数组中添加一个新的Object,但是看起来对象是正确创建的,但是当我检查数组的大小时,它总是为0.什么可以是吗?
var comments = new Array();
function validateComment() {
var x = document.forms["commentForm"]["commentSection"].value;
if (x == null || x == "") {
alert("There's nothing to comment, write something to proceed.");
return false;
} else {
var comment = {
firstName:"Name",
lastName:"Surname",
text:x
};
comments.push(comment);
}
}
感谢您的帮助。