读取 Radio 的值
2 <form id="form1" action="" method="">
3 <div><input type="radio" name="r" id="r1" value="一"><label for="r1">选项一</label></div>
4 <div><input type="radio" name="r" id="r2" value="二"><label for="r2">选项二</label></div>
5 <div><input type="radio" name="r" id="r3" value="三"><label for="r3">选项三</label></div>
6 <div><input type="button" value="检查选择项" onclick="javascript:Foo();"></div>
7 </form>
8
9 <script type="text/javascript" language="javascript">
10 <!--
11 function Foo()
12 {
13 var selectedIndex = -1;
14 var form1 = document.getElementById("form1");
15 var i = 0;
16
17 for (i=0; i<form1.r.length; i++)
18 {
19 if (form1.r[i].checked)
20 {
21 selectedIndex = i;
22 alert("您选择项的 value 是:" + form1.r[i].value);
23 break;
24 }
25 }
26
27 if (selectedIndex < 0)
28 {
29 alert("您没有选择任何项");
30 }
31 }
32 -->
33 </script>
3 <div><input type="radio" name="r" id="r1" value="一"><label for="r1">选项一</label></div>
4 <div><input type="radio" name="r" id="r2" value="二"><label for="r2">选项二</label></div>
5 <div><input type="radio" name="r" id="r3" value="三"><label for="r3">选项三</label></div>
6 <div><input type="button" value="检查选择项" onclick="javascript:Foo();"></div>
7 </form>
8
9 <script type="text/javascript" language="javascript">
10 <!--
11 function Foo()
12 {
13 var selectedIndex = -1;
14 var form1 = document.getElementById("form1");
15 var i = 0;
16
17 for (i=0; i<form1.r.length; i++)
18 {
19 if (form1.r[i].checked)
20 {
21 selectedIndex = i;
22 alert("您选择项的 value 是:" + form1.r[i].value);
23 break;
24 }
25 }
26
27 if (selectedIndex < 0)
28 {
29 alert("您没有选择任何项");
30 }
31 }
32 -->
33 </script>