现在的位置: 首页 > 综合 > 正文

JavaScript实现获取radio的值

2014年02月22日 ⁄ 综合 ⁄ 共 751字 ⁄ 字号 评论关闭

做web时用到的js的功能,备份一下.注意radio也有属性checked.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<script>
  function selectRadio(radioname,url){
    var aa = document.getElementsByName(radioname);
    for (var i=0; i<aa.length; i++)
    {
     if(aa[i].checked){
    window.location=url+aa[i].value;
  }
    }
  }

</script>
  <input name="button" type="button" onclick="return selectRadio('radiobutton','/cn/manager/project/');" value="提交"/>
  <br>
  <input type="radio" name="radiobutton" value="radiobutton1">
  <input type="radio" name="radiobutton" value="radiobutton2">
  <input type="radio" name="radiobutton" value="radiobutton3">
</p>
</body>
</html> 

抱歉!评论已关闭.