滄海一幻覺
2021-06-15 14:11:42
if(qty==0){$(this).find(".buy").removeAttr('checked');}else if(qty>0){$(this).find(".buy").attr('checked',true);}jquery檢測數(shù)量qty,默認(rèn)是checked="checked",但數(shù)量為0時,的確取削了打勾,但當(dāng)再次輸入其它數(shù)量時,源碼已顯示 checked='checked' 了,但瀏覽器中并未給它打勾,chrome,ie10均如此,是什么原因?代碼貌似沒有問題,但問題是的確不能再次打上勾
3 回答

慕斯709654
TA貢獻(xiàn)1840條經(jīng)驗 獲得超5個贊
if(qty==0){
$(this).find(".buy").removeAttr('checked');
}else if(qty>0){
$(this).find(".buy").each(function(){
$(this)[0].checked=true;
})
}
這么寫可以暫時滿足需求,但是$(this).find(".buy").attr('checked',true);為什么不可以,確實(shí)讓我也很費(fèi)解

慕萊塢森
TA貢獻(xiàn)1810條經(jīng)驗 獲得超4個贊
$(this).find(".buy").attr('checked',true)改成$(this).find(".buy").attr(''checked'',"checked");試試!
添加回答
舉報
0/150
提交
取消