Previously I summarized the issue about how jquery determines whether a check box is selected . Today I summarized how to determine whether a js check box is selected
JavaScript determines whether the checkbox is selected. The following is an example (there is now a set of checkboxes as follows):
<input type="checkbox" name="fruit" value="apple" />苹果 <input type="checkbox" name="fruit" value="orange" />橘子 <input type="checkbox" name="fruit" value="banana" />香蕉 <input type="checkbox" name="fruit" value="grape" />葡萄
The method to get the value of a set of checkboxes with name=fruit is as follows:
<script language="javascript"> function checkbox(){ var str=document.getElementsByName('fruit'); var strstrLen=str.length; var checkVal=''; for (i=0;i<strLen;i++){ if(str[i].checked==true){ checkVal+=str[i].value+','; } } if(checkVal==''){ alert("请先选择复选框~!"); }else{ alert("复选框的值是:"+checkVal); } } </script>
Combine it with the previous "JQuery method to determine whether a check box is selected" and learn together, you will definitely have unexpected gains!