当前位置: 代码迷 >> JavaScript >> js 判断checkbox是不是选中
  详细解决方案

js 判断checkbox是不是选中

热度:831   发布时间:2012-07-16 15:44:59.0
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?onclick="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?onclick="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?onclick="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?onclick="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> ? ?
  相关解决方案