分类:JS记事本 发布时间:2017-05-30 10:39:44 阅读: 作者:郑祥景
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="js/jquery-1.11.3.min.js"></script>
<script>
$(document).ready(function(){
//全选
$('#quanxuan').click(function(){
panduan = $("#quanxuan").prop("checked");
if(panduan == true){
$("input").prop("checked", 'checked');
}else{
$("input").prop("checked", false);
}
})
//反选
$('#fanxuan').click(function(){
$(".mode input").each(function(){
$(this).prop("checked", !$(this).prop("checked"));
})
})
//选项总个数
num = $(".mode input").size();
$('#num').text(num);
})
</script>
</head>
<body>
<p><input type="checkbox" value="全选" id="quanxuan"> 全选</p>
<div class="mode">
<p><input type="checkbox"/> I have a car</p>
<p><input type="checkbox"/> I have a car</p>
<p><input type="checkbox"/> I have a car</p>
<p><input type="checkbox"/> I have a car</p>
<p><input type="checkbox"/> I have a car</p>
<p><input type="checkbox"/> I have a car</p>
<p><input type="checkbox"/> I have a car</p>
<p><input type="checkbox"/> I have a car</p>
<p><input type="checkbox"/> I have a car</p>
</div>
<p><input type="button" value="反选" id="fanxuan"></p>
<p>选项总个数:<span id="num"></span></p>
</body>
</html>
编辑:郑祥景