日期:2014-05-16 浏览次数:20312 次
<html> <head> <title>js+dom获得单选选项</title> <script language="javascript" type="text/javascript"> function hd(){ var obj = document.getElementsByName("One"); for(var i = 0;i < obj.length; i ++){ if(obj[i].checked){ alert(obj[i].value); } } } </script> </head> <body> <label>A<input type="radio" value="A" name="One" id="One"/></label> <label>B<input type="radio" value="B" name="One" id="One"/></label> <label>C<input type="radio" value="C" name="One" id="One"/></label> <label>D<input type="radio" value="D" name="One" id="One"/></label> <input type="button" value="获得" onclick="hd()"/> </body> </html>