虽然我正在尝试计算数组的长度:
$('input:checkbox[name="promoOn[]"]').click( function(){
var attributes = [];
$('input:checkbox[name="promoOn[]"]:checked').each(function(index) {
attributes.push($(this).val());
$('#promo-on-total').html(attributes.length);
});
});
由于某种原因,array.length 不返回 0?结果如下:
Checkbox 1, checked = array.length = 1
Checkbox 2, checked = array.length = 2
Checkbox 2, unchecked = array.length = 2
Checkbox 1, unchecked = array.length = 1 (not 0???)
有什么想法可能是错的吗?