`

JS取radio单选按钮值的小例子(转自www.jbxue.com)

 
阅读更多

转自:http://www.jbxue.com/article/js/20653.html

发布时间:2014-05-11   编辑:kksky

分享一个js获取radio单选按钮中值的例子,有需要的朋友参考下。

例子,js取radio
 

复制代码代码示例:

<form method="post" name="form1">
    <label><input type="radio" name="radio" value="1-10 岁">1-10 岁</label>
    <label><input type="radio" name="radio" value="11 岁">11 岁</label>
    <label><input type="radio" name="radio" value="12-120 岁">12-120 岁</label>
    <input type="button" onclick="ok()" value="测试选择值">
  </form>

<form method="post" name="form2">
    <input type="text" name="textfield">
  </form>

<script language="javascript" type="text/javascript">
<!--
function ok()
{ www.jbxue.com
  var temp=document.getElementsByName("radio");
  for (i=0;i<temp.length;i++){
  //遍历Radio
    if(temp[i].checked)
      {alert("你选择了"+temp[i].value);
      //获取Radio的值
      document.form2.textfield.value="你选择了"+temp[i].value;
      //传递给另外一个表单
      }
  }
}
-->
</script>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics