<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>demo04.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="../js/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#ckbAll").click(function(){
$("input[name='fav']").attr("checked",true);
});
$("#ckbno").click(function(){
$("input[name='fav']").attr("checked",false);
});
$("#ckbrec").click(function(){
$("input[name='fav']").each(function(){
// $(this).attr("checked",!$(this).attr("checked"));
this.checked=!this.checked;//用的是Dom的屬性
});
});
});
</script>
</head>
<body>
<div>
<input type="checkbox" name="fav" value="看書(shū)1" checked="checked"/>看書(shū)1
<input type="checkbox" name="fav" value="看書(shū)2" checked="checked"/>看書(shū)2
<input type="checkbox" name="fav" value="看書(shū)3" checked="checked"/>看書(shū)3
<input type="checkbox" name="fav" value="看書(shū)4" checked="checked"/>看書(shū)4
</div>
<div>
<input type="button" id="ckbAll" value="全選"/><br/><br/>
<input type="button" id="ckbno" value="全不選"/><br/><br/>
<input type="button" id="ckbrec" value="反選"/><br/>
</div>
</body>
</html>
發(fā)表評(píng)論