<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
</head>
<body>
<div id="divckb">
<input type="checkbox" name="ckb1" value="1" />张三
<input type="checkbox" name="ckb2" value="2" />李四
<input type="checkbox" name="ckb3" value="3"/>王五
<input type="checkbox" name="ckb4" value="4" />赵六
</div>
<script>
$(function(){
$("#divckb input").each(function(){
$(this).change(function(){
var test= $(this).attr("checked");
if($(this).attr("checked")){
//此处写你的处理
//$("#divckb input").each(function(){
// //alert($(this).val()); //
// if(test== $(this).attr("checked")){
// $(this).attr("checked",false);
// //alert($(this).val()+"-1");
// }else{
// $(this).attr("checked",false);
// //alert($(this).val()+"-2");
// }
//});
}
else{
$(this).attr("checked",true);
$(this).siblings().each(function(){
$(this).attr("checked",false);
});
//此处写你的处理
}
});
});
});
</script>
</body>
</html>
转载于:https://blog.51cto.com/kangsafe/1530338