checkbox全選/取消全選
阿新 • • 發佈:2017-05-31
fun log 按鈕 () odi checked input rop cti
//checkbox全選/取消全選 $(function() { $("#checkAll").click(function() { if(this.checked){ $("input[name=‘cbxCommodity‘]").prop("checked","checked"); }else{ $("input[name=‘cbxCommodity‘]").removeAttr("checked"); } }); var $cbx = $("input[name=‘cbxCommodity‘]"); $cbx.click(function(){ var num = $cbx.length;//總的checkbox數量 var num_checked = $("input[name=‘cbxCommodity‘]:checked").length;//選中的數量 if(num == num_checked){ $("input[name=‘checkAll‘]").prop("checked","checked"); }else{ $("input[name=‘checkAll‘]").removeAttr("checked"); } }); });
checkAll 是全選按鈕
cbxCommodity 是單選的checkbox name
checkbox全選/取消全選