jQuery全选/反选checkbox

时间:2023-03-08 15:59:14
jQuery全选/反选checkbox
<!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>