使用jQuery練習全選-取消-反選-顯示選擇內容等功能代碼,jquery全選
<span style="font-size:24px;color:#ff0000;">部長練習全選-取消-反選-顯示選擇內容等功能代碼:</span>
<!doctype html><html><head><meta charset="gb2312"><title>部長練習全選-取消-反選-顯示選擇內容等功能</title><script src="js/jquery-1.11.1.min.js"></script><script>$(document).ready(function(e) { //實現全選功能 $(':input[value=全選]').click(function(){ //alert($(this).val()); $('form :checkbox').prop("checked", true); }); //實現取消功能 $(':input[value=取消]').click(function(){ //$(':checkbox').removeAttr('checked'); //$(':checkbox').attr('checked',false); $('form :checkbox').prop("checked",false); }); //實現反選功能 $(':input[value=反選]').click(function(){ $('form :checkbox').each(function(index, element) { $(this).prop('checked',!$(this).prop('checked')); });; }); //實現第二個全選的功能 $('#myall').change(function(){ //alert($(this).prop('checked')); if($(this).prop('checked')){ $('form :checkbox').prop("checked", true); $(this).next('span').html('取消'); }else{ $('form :checkbox').prop("checked",false); $(this).next('span').html('全選'); } }); //實現顯示選擇的功能 $(':input[value=顯示選擇]').click(function(){ var t = ''; $('form :checked').each(function(index, element) { t+=$(this).val(); }); alert(t); });});</script></head><body><form><label><input type="checkbox" name="love[]" value="音樂">音樂</label><label><input type="checkbox" name="love[]" value="運動">運動</label><label><input type="checkbox" name="love[]" value="看書">看書</label><label><input type="checkbox" name="love[]" value="玩遊戲">玩遊戲</label><label><input type="checkbox" name="love[]" value="看電視">看電視</label><label><input type="checkbox" name="love[]" value="遊戲">遊戲</label><label><input type="checkbox" name="love[]" value="上網">上網</label></form><hr><input type="button" value="全選"> <input type="button" value="反選"> <input type="button" value="取消"> <input type="button" value="顯示選擇"><hr><label><input type="checkbox" id="myall"><span>全選</span></label></body></html>
jquery全選刪除
這裡給你個全選或全不選的方法,刪除的方法就是把table裡面的對應的tr刪除掉,並更新資料庫,$(function () {
$(".ck").click(function () {
if ($(".ck").attr("checked") == "checked") {
$("input:[type='checkbox']").attr("checked", "checked");
}
else {
$("input:[type='checkbox']").removeAttr("checked");
}
});
});
jquery 篩選器的使用,做全選,反選,大量刪除用的
$.each($(".mp"),function(){
alert( $(this).val() );
});