<!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>
<title></title>
<script src="../Scripts/jquery-1.6.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("input[name='hobby']").click(function () {
$("input[name='hobby']:checked").length == $("input[name='hobby']").length ? $("#checkAll").attr("checked", true) : $("#checkAll").attr("checked", false);
});
$("#checkAll").click(function () {
$("input[name='hobby']").attr("checked", this.checked);
});
});
</script>
</head>
<body>
<form action="test.htm" method="post">
<input id="checkAll" type="checkbox" />全选
<br />
<input type="checkbox" name="hobby" value="1" />
<input type="checkbox" name="hobby" value="2" />
<input type="checkbox" name="hobby" value="1" />
<input type="checkbox" name="hobby" value="1" />
<input type="checkbox" name="hobby" value="1" />
</form>
</body>
</html>
复选框全选JS代码
最新推荐文章于 2024-04-02 19:39:43 发布