页面如下:

源码:

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>demo04.html</title>
  5. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  6. <meta http-equiv="description" content="this is my page">
  7. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  8. <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
  9. <script type="text/javascript" src="../js/jquery-1.9.1.js"></script>
  10. <script type="text/javascript">
  11. $(document).ready(function(){
  12. $("#ckbAll").click(function(){
  13. $("input[name='fav']").attr("checked",true);
  14. });
  15. $("#ckbno").click(function(){
  16. $("input[name='fav']").attr("checked",false);
  17. });
  18. $("#ckbrec").click(function(){
  19. $("input[name='fav']").each(function(){
  20. // $(this).attr("checked",!$(this).attr("checked"));
  21. this.checked=!this.checked;//用的是Dom的属性
  22. });
  23. });
  24. });
  25. </script>
  26. </head>
  27. <body>
  28. <div>
  29. <input type="checkbox" name="fav" value="看书1" checked="checked"/>看书1
  30. <input type="checkbox" name="fav" value="看书2" checked="checked"/>看书2
  31. <input type="checkbox" name="fav" value="看书3" checked="checked"/>看书3
  32. <input type="checkbox" name="fav" value="看书4" checked="checked"/>看书4
  33. </div>
  34. <div>
  35. <input type="button" id="ckbAll" value="全选"/><br/><br/>
  36. <input type="button" id="ckbno" value="全不选"/><br/><br/>
  37. <input type="button" id="ckbrec" value="反选"/><br/>
  38. </div>
  39. </body>
  40. </html>
posted on 2013-03-21 20:17  z流星追月  阅读(132)  评论(0编辑  收藏  举报