[英]issues with javascript checkboxes issues
the following code just says unexpected identifier;
以下代码仅表示unexpected identifier;
var icheckBoxes = $('input[type="checkbox"]');
for(int i=0; i < icheckBoxes.length; i++) {
if (!icheckBoxes[i].is(":checked")) {
$('input[type="checkbox').addClass('has-error');
AgreeIsActive = false;
$('#AgreementSubmit').prop('disabled', false);
return;
}
}
Seems to be the int
as the culprit but i tried it to change it to var
but no success and got a different error: 似乎是int
作为元凶,但我尝试将其更改为var
但没有成功,并得到了另一个错误:
Uncaught TypeError: icheckBoxes[i].is is not a function
Update#1 更新#1
New Code added with the help 在帮助下添加了新代码
var icheckBoxes = $('input[type="checkbox"]');
alert(icheckBoxes.length);
for(var i=0; i < icheckBoxes.length; i++) {
alert(i);
//if (!icheckBoxes[i].is(":checked")) {
if(!icheckBoxes.eq(i).is(":checked")) {
alert(i);
$('input[type="checkbox').addClass('has-error');
AgreeIsActive = false;
$('#AgreementSubmit').prop('disabled', false);
return;
}
}
it says the length is 4 and then it goes inside and it alerts 4 times 0 and the next alert which is inside the if condition, it just alerts it 1 time and that is also 0 它说长度为4,然后进入内部,并发出4次0警报,而下一个处于if条件内的警报则发出1次警报,也为0
icheckBoxes[i].is(":checked")
should be 应该
icheckBoxes.eq(i).is(":checked")
[]
breaks the element out of the jQuery object and is()
is a jQuery method. []
将元素从jQuery对象中分离出来,而is()
是jQuery方法。
Also as a side note, $('input[type="checkbox')
is missing the "]
on the end of it to make it a valid selector. 另外请注意, $('input[type="checkbox')
在其末尾缺少"]
以使其成为有效的选择器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.