用JS(JavaScript)获取表单中radio标签值
很多人想从radio中获取值,但radio获得的是一个字符串数组,所以要注意如果取值。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
01.<html>
02.<script language="javascript">
03. function on_submit()
04. {
05. var temp=document.getElementsByName("operator");
06. for(i=0;i<temp.length;i++)
07. {
08. if(temp[i].checked)
09. {
10. alert(temp[i].value);
11. break;
12. }
13. }
14. }
15.<script>
16.<body>
17.
18.<form name="form1" action="" method="post">
19. <input type="radio" name="operator" value="add" checked/>+
20. <input type="radio" name="operator" value="sub"/>-
21. <input type="radio" name="operator" value="mul"/>*
22. <input type="radio" name="operator" value="div"/>/
23. <input type="button" name="bt" value="测试" onclick="on_submit()"/>
24.</form>
25.
26.</body>
27.</html>