jquery实现点击一个复选框,让其它复选框都选中,反之再次点击都取消
发布网友
发布时间:2022-05-15 10:28
我来回答
共1个回答
热心网友
时间:2022-05-15 11:57
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script class="jquery library" src="/js/sandbox/jquery/jquery-1.8.2.min.js" type="text/javascript"></script>
<title>
RunJS 演示代码
</title>
<script>
$(function(){
var cks = $(":checkbox:gt(0)");
var fk = $(":checkbox:first").click(function(){
cks.prop("checked", $(this).prop("checked"));
});
cks.click(function(){
if(!$(this).prop("checked")){
fk.prop("checked",false);
}else{
if(cks.filter(":not(:checked)").length == 0){
fk.prop("checked",true);
}
}
});
});
</script>
</head>
<body>
<label><input type="checkbox" />全选</label>
<label><input type="checkbox" />A</label>
<label><input type="checkbox" />B</label>
<label><input type="checkbox" />C</label>
<label><input type="checkbox" />D</label>
</body>
</html>