Radio的使用,获取Radio的所选的值(Checkbox的使用与之类似)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">...
function ShowSexSelect()
...{
var Sex;
for(var i = 0; i < document.all.sex.length; i++)
...{
if (document.all.sex[i].checked == true)...{ Sex=document.all.sex[i].value;}
}
alert(Sex);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="0" cellpadding="0" cellspacing="2" width="800px">
<tr>
<td id="td_Sex">性别:<input id="rdoMen" name="sex" type="radio" checked="checked" value="男" />男 <input id="rdoWomen" name="sex" type="radio" value="女"/>女</td>
</tr>
<tr>
<td><input id="Button1" type="button" value="ShowSexSelect" onclick="ShowSexSelect();"/></td>
</tr>
</table>
<div>
</form>
</body>
</html>
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">...
function ShowSexSelect()
...{
var Sex;
for(var i = 0; i < document.all.sex.length; i++)
...{
if (document.all.sex[i].checked == true)...{ Sex=document.all.sex[i].value;}
}
alert(Sex);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="0" cellpadding="0" cellspacing="2" width="800px">
<tr>
<td id="td_Sex">性别:<input id="rdoMen" name="sex" type="radio" checked="checked" value="男" />男 <input id="rdoWomen" name="sex" type="radio" value="女"/>女</td>
</tr>
<tr>
<td><input id="Button1" type="button" value="ShowSexSelect" onclick="ShowSexSelect();"/></td>
</tr>
</table>
<div>
</form>
</body>
</html>
要注意的是:Radio的name的值一定要一致,这样它们才是一组!