首页 > 其他 > 详细

复选框获取值

时间:2016-09-06 18:24:12      阅读:222      评论:0      收藏:0      [点我收藏+]
<script>
function checkbox()
{
var str=document.getElementsByName("box");
var objarray=str.length;
var chestr="";
j=0;
for (i=0;i<objarray;i++)
{
  if(str[i].checked == true)
  {
      ++j;
      if(chestr==""){
           chestr+=str[i].value;
      }else{
           chestr+=","+str[i].value;
      }
  }
}
if(chestr == "")
{
  alert("请先选择一个爱好~!");
}
else
{
  alert("您先择的是:"+chestr+" 长度::"+j);
}
}
</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="提交" />

 

复选框获取值

原文:http://www.cnblogs.com/haiyangsvs/p/5846716.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!