判断checkbox选中

王朝学院·作者佚名  2016-05-23
窄屏简体版  字體: |||超大  

判断checkbox选中源码如下,仅限参考,直接复制即可:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script>function checkbox(){var str=document.getElementsByName("box");var objarray=str.length;var chestr="";for (i=0;i<objarray;i++){ if(str[i].checked == true) { chestr+=str[i].value+","; }}if(chestr == ""){ alert("请先选择一个爱好~!");}else{ alert("您先择的是:"+chestr);}}</script>选择您的爱好: <input type="checkbox" name="box" id="box1" value="跳水" />跳水 <input type="checkbox" name="box" id="box2" value="跑步" />跑步 <input type="checkbox" name="box" id="box3" value="听音乐" />听音乐 <input type="button" name="button" id="button" onclick="checkbox()" value="提交" />

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航