<!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="看書1" checked="checked"/>看書1
<input type="checkbox" name="fav" value="看書2" checked="checked"/>看書2
<input type="checkbox" name="fav" value="看書3" checked="checked"/>看書3
<input type="checkbox" name="fav" value="看書4" checked="checked"/>看書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>
發表評論