,而我試圖找出一個數組的長度:數組的長度不返回到0
$('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???)
任何想法可能是錯誤的?
發佈代碼,您在哪裏彈出數組中的項目 –
是我還是當您未選中複選框2 array.length不減少? –
'var attributes = [];'會重新初始化數組?不是?意味着每次點擊都會有'0'長度。所以減少是不需要的。 – Dev