本篇文章是关于复选框的,有2种形式:1、全选、反选由2个按钮实现;2、全选、反选由一个按钮实现。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>复选框demo</title>
<script src="../js/jquery-1.10.2.js" type="text/javascript"></script>
<style>
body{ text-align:center}
.con{ margin:100px auto; width:800px; height:400px; border:1px solid #F00; padding-top: 50px;}
</style>
</head>
<body>
<div class="con">
<span><input type='checkbox' name='select' onclick='allSelect()'>全选</span>
<span><input type='checkbox' name='cancel' onclick='unAllSelect()'>反选</span>
<span><input type='checkbox' name='fruit' />苹果</span>
<span><input type='checkbox' name='fruit' />香蕉</span>
<span><input type='checkbox' name='fruit' />梨子</span>
<span><input type='checkbox' name='fruit' />桃子</span>
<span><input type='checkbox' name='fruit' />西瓜</span>
<br><br><br>
<span><input type='checkbox' id="allBook" name='allBook' />全选</span>
<span><input type='checkbox' name='book' />老子</span>
<span><input type='checkbox' name='book' />尚书</span>
<span><input type='checkbox' name='book' />周易</span>
<span><input type='checkbox' name='book' />诗经</span>
<span><input type='checkbox' name='book' />孟子</span>
<span><input type='checkbox' name='book' />中庸</span>
<script type="text/javascript">
//全选
function allSelect(){
$("input[name='fruit']").prop("checked", "checked");
$("input[name='cancel']").removeAttr("checked");
}
//反选
function unAllSelect(){
$("input[name='fruit']").removeAttr("checked");
$("input[name='select']").removeAttr("checked");
}
//单选
$("#allBook").click(function(){
if(this.checked){
// $("input[name='book']").attr("checked", true);
$("input[name='book']").prop("checked", "checked");
}else{
// $("input[name='book']").attr("checked", false);
$("input[name='book']").removeAttr("checked");
}
});
</script>
</div>
</body>
</html>另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。