首页 > 技术文章 > JQ 全选、全不选

yangjinwang 2016-10-31 19:49 原文

$(document).ready(function() {

$("#isalldebt").click(function()
{
if ($(this).attr("checked")) { // 全选 

$("input[name='debt_type']").each(function(){ 
$(this).attr("checked", true); 
}); 
}
else { // 取消全选 

$("input[name='debt_type']").each(function(){ 
$(this).attr("checked", false); 
}); 
}
});


});

=======================下面html代码 

 

<input id="1" name="debt_type" value="0" type="checkbox">

<input id="2" name="debt_type" value="1" type="checkbox">

<input id="3" name="debt_type" value="2" type="checkbox">
 

<input type="checkbox" id="isalldebt"> 
<label for="isalldebt" onclick="isalldebt()" >全选</label>

 

 

 

推荐阅读