全選全不選

走過10余年,我們已為眾多企業(yè)及政府機關(guān)提供專業(yè)的互聯(lián)網(wǎng)服務(wù)。我們不只是一家專業(yè)網(wǎng)站設(shè)計公司;我們對營銷、技術(shù)、服務(wù)都有自己獨特見解,創(chuàng)新互聯(lián)采取“創(chuàng)意+綜合+營銷”一體化的方式為您提供更專業(yè)的服務(wù)!創(chuàng)新互聯(lián)經(jīng)歷的每一步也許不一定是最完美的,但每一步都有值得深思的意義。
$("#cbxAll").click(function(){
if(this.checked)?{
$("input[name='你的checkBox組的name']").prop("checked",true);
}
else?{
$("input[name='你的checkBox組的name']").prop("checked",false);
}
});
至于刪除功能,這個是需要ajax去做了
script
$("#seleall").click(function(){
$(":checkbox").attr("checked",true);
})
$("#selenone").click(function(){
$(":checkbox").attr("checked",false);
})
$("#selere").click(function(){
$(":checkbox").each(function(){
$(this).attr("checked",!$(this).attr("checked"))
});
})
/script
需要三個復選框。按個按鈕
可實現(xiàn)全選,全不選,反選
HTML代碼:
table
tr
tdinput type="checkbox" name="b"全選/tdtd內(nèi)容/td
/tr
tr
tdinput type="checkbox" name="a"/tdtd復選1/td
/tr
tr
tdinput type="checkbox" name="a"/tdtd復選2/td
/tr
tr
tdinput type="checkbox" name="a"/tdtd復選3/td
/tr
tr
tdinput type="checkbox" name="a"/tdtd復選4/td
/tr
tr
tdinput type="checkbox" name="a"/tdtd復選5/td
/tr
tr
tdinput type="checkbox" name="a"/tdtd復選6/td
/table
JAVASCRIPT代碼:
script
$("input[name='b']").click(function(){
//判斷當前點擊的復選框處于什么狀態(tài)$(this).is(":checked") 返回的是布爾類型
if($(this).is(":checked")){
$("input[name='a']").prop("checked",true);
}else{
$("input[name='a']").prop("checked",false);
}
});
/script
3
這樣就實現(xiàn)了全選和全不選。
//所有checkbox跟著全選的checkbox走。 $('[name=items]:checkbox').attr("checked", this.checked );});$('[name=items]:checkbox').click(function(){ //定義一個臨時變量,避免重復使用同一個選擇器選擇頁面中的元素,提升程序效率。 var $tmp=$('[name=items]:checkbox'); //用filter方法篩選出選中的復選框。并直接給CheckedAll賦值。 $('#CheckedAll').attr('checked',$tmp.length==$tmp.filter(':checked').length); /* //一行做過多的事情需要寫更多注釋。復雜選擇器還可能影響效率。因此不推薦如下寫法。 $('#CheckedAll').attr('checked',!$('[name=items]:checkbox').filter(':not(:checked)').length);*/});//輸出值$("#send").click(function(){ var str="你選中的是:\r\n"; $('[name=items]:checkbox:checked').each(function(){ str+=$(this).val()+"\r\n";})alert(str);});});/script/headbodyform method="post" action="" 你愛好的運動是?input type="checkbox" id="CheckedAll" /全選/全不選br/ input type="checkbox" name="items" value="足球"/足球 input type="checkbox" name="items" value="籃球"/籃球 input type="checkbox" name="items" value="羽毛球"/羽毛球 input type="checkbox" name="items" value="乒乓球"/乒乓球br/
當前題目:jquery全選全不選,jquery全選全不選的實現(xiàn)
本文鏈接:http://chinadenli.net/article29/dsgddjh.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導航、動態(tài)網(wǎng)站、企業(yè)建站、服務(wù)器托管、自適應(yīng)網(wǎng)站、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)