jquery checkbox

3 篇文章 0 订阅
  1. <!DOCTYPE html PUBLIC  "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >   
  2. <html xmlns="http://www.w3.org/1999/xhtml" >   
  3. <head>   
  4. <meta http-equiv="Content-Type"  content= "text/html; charset=gb2312"  />   
  5. <title>louis-blog >> jQuery 对checkbox的操作</title>   
  6. <script type='text/javascript'  src= "../jquery.js" ></script>   
  7. <SCRIPT LANGUAGE="JavaScript" >   
  8. <!--   
  9. $("document" ).ready(function(){   
  10. $("#btn1" ).click(function(){   
  11. $("[name='checkbox']" ).attr( "checked" , 'true' ); //全选    
  12. })   
  13. $("#btn2" ).click(function(){   
  14. $("[name='checkbox']" ).removeAttr( "checked" ); //取消全选    
  15. })   
  16. $("#btn3" ).click(function(){   
  17. $("[name='checkbox']:even" ).attr( "checked" , 'true' ); //选中所有奇数    
  18. })   
  19. $("#btn4" ).click(function(){   
  20. $("[name='checkbox']" ).each(function(){ //反选    
  21. if ($( this ).attr( "checked" )){   
  22. $(this ).removeAttr( "checked" );   
  23. }   
  24. else {   
  25. $(this ).attr( "checked" , 'true' );   
  26. }   
  27. })   
  28. })   
  29. $("#btn5" ).click(function(){ //输出选中的值    
  30. var str="" ;   
  31. $("[name='checkbox'][checked]" ).each(function(){   
  32. str+=$(this ).val()+ "\r\n" ;   
  33. //alert($(this).val());    
  34. })   
  35. alert(str);   
  36. })   
  37. })   
  38. -->   
  39. </SCRIPT>   
  40. </HEAD>   
  41. <body style="text-align:center;margin: 0 auto;font-size: 12px;" >   
  42. <div style="border: 1px solid #999; width: 500px; padding: 15px; background: #eee; margin-top: 150px;" >   
  43. <form name="form1"  method= "post"  action= "" >   
  44. <input type="button"  id= "btn1"  value= "全选" >   
  45. <input type="button"  id= "btn2"  value= "取消全选" >   
  46. <input type="button"  id= "btn3"  value= "选中所有奇数" >   
  47. <input type="button"  id= "btn4"  value= "反选" >   
  48. <input type="button"  id= "btn5"  value= "获得选中的所有值" >   
  49. <br><br>   
  50. <input type="checkbox"  name= "checkbox"  value= "checkbox1" >   
  51. checkbox1   
  52. <input type="checkbox"  name= "checkbox"  value= "checkbox2" >   
  53. checkbox2   
  54. <input type="checkbox"  name= "checkbox"  value= "checkbox3" >   
  55. checkbox3   
  56. <input type="checkbox"  name= "checkbox"  value= "checkbox4" >   
  57. checkbox4   
  58. <input type="checkbox"  name= "checkbox"  value= "checkbox5" >   
  59. checkbox5   
  60. <input type="checkbox"  name= "checkbox"  value= "checkbox6" >   
  61. checkbox6   
  62. </form>   
  63. </div>   
  64. </body>   
  65. </HTML>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值