jquery(复选框全选)

<!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="heiheihei/jquery-1.11.2.min.js"></script>
</head>

<body>
<h1>全选效果</h1>
<div><input type="checkbox" value="qx" id="qx" />全选</div>
<br />

<div>
<input type="checkbox" value="1" class="ck" /> polo
<input type="checkbox" value="1" class="ck" /> 迈巴赫
<input type="checkbox" value="1" class="ck" /> 长城
<input type="checkbox" value="1" class="ck" /> 兰博基尼
<input type="checkbox" value="1" class="ck" /> 法拉利
<input type="checkbox" value="1" class="ck" /> 蚯蚓
<input type="checkbox" value="1" class="ck" /> 激励
<input type="checkbox" value="1" class="ck" /> 萨拉黑
<input type="checkbox" value="1" class="ck" /> 巴扎黑

</div>
</body>
<script type="text/javascript">
$("#qx").click(function(){
    var xz = $(this).prop("checked");  //prop 只在写复选框时使用
    //var xz = $(this).prop("checked");
    $(".ck").prop("checked",xz);
    })

</script>
</html>

原文地址:https://www.cnblogs.com/zhangbaobao/p/6841329.html