jQuery全选/反选checkbox

时间:2022-02-14 10:45:21
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>checkbox全选/反选</title>
<script src="jquery.js"> </script>
<script type="text/javascript">
$(document).ready(
function(){
$(
"#check").change(function(){
//全选/反选所有name="goods"的checkbox
$("input[name='goods']").prop("checked",this.checked);
//全选/反选所有checkbox
//$("input[type='checkbox']").prop("checked",this.checked);
});
});
</script>
</head>
<body>
<center>
全选/反选
<input type="checkbox" id="check"/><br/>
<input type="checkbox" name="goods"/><br/>
<input type="checkbox" name="goods"/><br/>
<input type="checkbox" name="goods"/><br/>
<input type="checkbox" name="goods"/><br/>
<input type="checkbox" name="goods"/><br/>
<input type="checkbox" name="goods"/><br/>
<input type="checkbox" name="goods"/><br/>
<input type="checkbox" name="goods"/><br/>
<input type="checkbox" name="goods"/><br/>
<input type="checkbox" name="goods"/><br/>
<input type="checkbox" name="goods"/><br/>
</center>
</body>
</html>