我一直在破坏我的大脑,试图弄清楚为什么我在下面的代码中第一次按下时,为数组statusIdValues得到一个未定义的错误。它在一个准备就绪的功能中被初始化,并在复选框状态改变时被推入。jQuery数组未定义错误
$(document).ready(function() {
var statusIdValues = [];
$(':checkbox').change(function() {
if ($(this).is(":checked")) {
statusIdValues.push($(this).attr("value"));
}
else {
var index= statusIdValues.indexOf($(this).attr("value"));
if (index > -1) {
statusIdValues.splice(index, 1);
}
});
});
任何帮助,将不胜感激。
'array.indexOf($(本).attr(“value”));'什么是数组? –
错字,虐待更新 –