jquery全选反选--解决第二次点击不能选中问题
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<meta charset="UTF-8" />
<script src="js/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(function($) {
//全选~反选
$("#Control").click(function(){
var val_a="全选",
val_b="反选",
cho=$(this).val();
check=$("#result input");
if(cho==val_a){
$(this).val(val_b);
// check.attr("checked","true") //用attr会导致第二次点击不能选中
check.prop("checked","true")
console.log(check);
}else{
$(this).val(val_a);
check.removeAttr("checked","true")
}
})
})
</script>
</head>
<body>
<input id="Control" type="button" value="全选"/>
<div id="result">
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
</div>
</body>
</html>
浙公网安备 33010602011771号