首页 > 代码库 > 读取radio的value值

读取radio的value值

 1 <!DOCTYPE html>
 2 <html>  
 3 <head>
 4  <script language="javascript" defer="defer">
 5 //document.getElementById("submitBtn")["onclick"]=function ()
 6 function test(){
 7  var tag=false;
 8  for(i=0;i<document.form1.radioGroup.length;i++)
 9  {
10   if(form1.radioGroup[i].checked)
11   {
12   alert(form1.radioGroup[i].value);
13   //tag=true;
14   return false;
15   }
16   else
17  {
18    alert("please check one radio");
19     //i=document.form1.radioGroup.length;
20     return false;
21   }
22   
23  }
24 }
25 
26  //if (tag) {
27   //  alert("succusefully!");
28 
29 // }
30  //else
31  //{
32   //  alert("please choosee....");
33  //}
34 //}
35   </script>  
36   </head>
37   <body>  
38   <form name="form1">
39   <input  type="radio"   name="radioGroup" value="http://www.mamicode.com/1"/>  
40   <input  type="radio"   name="radioGroup" value="http://www.mamicode.com/2"/>  
41   <input  type="radio"   name="radioGroup" value="http://www.mamicode.com/3"/>  
42   <input  type="radio"   name="radioGroup" value="http://www.mamicode.com/4"/>  
43   <input  type="radio"   name="radioGroup" value="http://www.mamicode.com/5"/>  
44   <input  type="radio"   name="radioGroup" value="http://www.mamicode.com/6"/>  
45   <input name="按钮" type="button" id="submitBtn" onclick="test()" value="http://www.mamicode.com/button"/>
46   </form>
47   </body> 
48 
49 </html>
View Code