js 判断checkbox是否选中

Java代码    收藏代码
  1. //第几个没有选     
  2. <input type="checkbox" name="checkbox1" checked>     
  3. <input type="checkbox" name="checkbox1">     
  4. <input type="checkbox" name="checkbox1" checked>     
  5. <input type="checkbox" name="checkbox1">     
  6. <input type="checkbox" name="checkbox1">     
  7. <script language=javascript>     
  8. function check(obj)     
  9. {     
  10.     
  11. for(i=0;i<document.all(obj).length;i++)     
  12. {     
  13. if(!document.all(obj)[i].checked)alert("第"+(i+1)+"个没有选择")     
  14. }     
  15. }     
  16. </script>     
  17. <input type=button οnclick="check('checkbox1')" value="检测">     
  18.     
  19.     
  20. //一个也没有选     
  21.     
  22.     
  23. <input type="checkbox" name="test">     
  24. <input type="checkbox" name="test">     
  25. <input type="checkbox" name="test">     
  26. <input type="checkbox" name="test">     
  27. <input type="checkbox" name="test">     
  28. <Script Language="JavaScript">     
  29. function check(obj){     
  30. for(i=0;i<document.all(obj).length;i++){     
  31. if(document.all(obj)(i).checked){     
  32. return;     
  33. }     
  34. }     
  35. window.alert('一个也没有选!');     
  36. }     
  37. </Script>     
  38. <input type=button οnclick="check('test');" value="检测">     
  39.   
  40. //第几个没有选  
  41. <input type="checkbox" name="checkbox1" checked>  
  42. <input type="checkbox" name="checkbox1">  
  43. <input type="checkbox" name="checkbox1" checked>  
  44. <input type="checkbox" name="checkbox1">  
  45. <input type="checkbox" name="checkbox1">  
  46. <script language=javascript>  
  47. function check(obj)  
  48. {  
  49.   
  50. for(i=0;i<document.all(obj).length;i++)  
  51. {  
  52. if(!document.all(obj)[i].checked)alert("第"+(i+1)+"个没有选择")  
  53. }  
  54. }  
  55. </script>  
  56. <input type=button οnclick="check('checkbox1')" value="检测">  
  57.   
  58.   
  59. //一个也没有选  
  60.   
  61.   
  62. <input type="checkbox" name="test">  
  63. <input type="checkbox" name="test">  
  64. <input type="checkbox" name="test">  
  65. <input type="checkbox" name="test">  
  66. <input type="checkbox" name="test">  
  67. <Script Language="JavaScript">  
  68. function check(obj){  
  69. for(i=0;i<document.all(obj).length;i++){  
  70. if(document.all(obj)(i).checked){  
  71. return;  
  72. }  
  73. }  
  74. window.alert('一个也没有选!');  
  75. }  
  76. </Script>  
  77. <input type=button οnclick="check('test');" value="检测">   
  78.   
  79.   
  80.   
  81. Java代码   
  82. <script language="javascript">     
  83. function checkme()     
  84. { var checkmemberid;//定义团员     
  85. var checkcontentid;//定义文章     
  86.    checkmemberid=false;     
  87.    checkcontentid=false;     
  88. //判断团员是否选中     
  89.  if (document.all.memberid.checked==true)//只有一个单选钮的情况     
  90.   {      
  91.     checkmemberid=true;     
  92.          
  93.   }     
  94. for(i=0;i<document.all.memberid.length;i++)//有一组单选钮的情况     
  95. {     
  96. if(document.all.memberid(i).checked)     
  97. {     
  98. checkmemberid=true;      
  99. }     
  100. }     
  101. //判断文章是否选中     
  102. if (document.all.contentid.checked==true)//只有一个单选钮的情况     
  103.    {      
  104.     checkcontentid=true;     
  105.    }     
  106. for(i=0;i<document.all.contentid.length;i++)//有一组单选钮的情况     
  107. {     
  108. if(document.all.contentid(i).checked)     
  109. {     
  110. checkcontentid=true;      
  111. }     
  112. }      
  113. //将结果返回     
  114. if (checkmemberid==false)     
  115.    { window.alert("请选择团员!");     
  116.     return false;     
  117.    }     
  118. else if(checkcontentid==false)     
  119. {     
  120.     window.alert("请选择文章!");     
  121.     return false;     
  122. }     
  123. return true;     
  124.     
  125.     
  126. }     
  127.     
  128.     
  129. </script>    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值