日期:2014-05-18  浏览次数:20692 次

一个简单问题,关于radio的选择.
<%@   page   contentType= "text/html;   charset=utf-8 "   language= "java "   import= "java.sql.* "   errorPage= " "   %>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=utf-8 "   />
<title> </title>
</head>
<script   language= "javascript ">
function   SelectUser()
{
alert(document.getElementById( "R_address ").value);
}
</script>

<body>
<label>
<input   type= "radio "     id= "R_address "   name= "R_address "   value= "888 "     checked= "checked "       onclick= "alert(this.value) "/>
发货地址一   </label>
<label>
<input   type= "radio "   id= "R_address "   name= "R_address "   value= "2 "           onclick= "alert(this.value) "/>
发货地址二   </label>
</body>
</html>

===
结果为什么一直是1
我想要的是哪个radio选择了,就输出对应的value值?怎样实现?


------解决方案--------------------
<%@ page contentType= "text/html; charset=utf-8 " language= "java " import= "java.sql.* " errorPage= " " %>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=utf-8 " />
<title> </title>
</head>
<script language= "javascript ">
function SelectUser()
{
alert(document.getElementByName( "R_address ").value);
}
</script>

<body>
<label>
<input type= "radio " id= "R_address1 " name= "R_address " value= "888 " checked= "checked " onclick= "alert(this.value) "/>
发货地址一 </label>
<label>
<input type= "radio " id= "R_address2 " name= "R_address " value= "2 " onclick= "alert(this.value) "/>
发货地址二 </label>
</body>
</html>

------解决方案--------------------
你得到的是表示“选中”,当然是1了啊!
你可以遍历这两个radio,看看哪个被选中了,记录下来,就可以了。
------解决方案--------------------
id不能相同,name应该相同
------解决方案--------------------
不过我把你的第一行换成这样
<%@page contentType= "text/html; charset=GBK " %>
<%@ page import= "java.sql.* " %>