现在的位置: 首页 > 综合 > 正文

[JavaScript] Radio的使用

2017年11月19日 ⁄ 综合 ⁄ 共 851字 ⁄ 字号 评论关闭

 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="男" />&nbsp;<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的值一定要一致,这样它们才是一组!

抱歉!评论已关闭.