用JavaScript怎么得到服务器控件RedioButtonList的值?

tomedai 2009-05-03 10:37:16
<script language="javascript" type="text/javascript">
function CheckForm() {
var sex = document.getElementById("<%= rdolSex.ClientID %>");
if(sex.value == "" ) {
alert("请选择性别!");
return false;
}
return true;
}
</script>



<asp:RadioButtonList ID="rdolSex" runat="server" RepeatDirection="Horizontal" Width="150px" BorderColor="#B5CEE4" BorderStyle="Solid" BorderWidth="1px">
<asp:ListItem Value="男">男</asp:ListItem>
<asp:ListItem Value = "女">女</asp:ListItem>
</asp:RadioButtonList></td>
...全文
183 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tomedai 2009-05-03
  • 打赏
  • 举报
回复
结合两位的高见,解决了,谢谢!
littlehand 2009-05-03
  • 打赏
  • 举报
回复

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script>
function GetRblValue() {
var ipts = document.getElementById("RadioButtonList1").getElementsByTagName("input");
var value;
for (i = 0; i < ipts.length; i++) {
if (ipts[i].checked) {
value = ipts[i].value;
break;
}
}

alert(value);
//return value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Value="1">a</asp:ListItem>
<asp:ListItem Value="2">b</asp:ListItem>
<asp:ListItem Value="3">c</asp:ListItem>
<asp:ListItem Value="4">d</asp:ListItem>
</asp:RadioButtonList>

<input type="button" value="得到radiobuttonlist的值" onclick='GetRblValue()' />
</div>
</form>
</body>
</html>
蓝海D鱼 2009-05-03
  • 打赏
  • 举报
回复
js取ASP.NET服务器控件RadioButtonList选中的值

<script type="text/javascript">

//取得RadioButtonList客户端id 如服务器端控件RadioButtonList的服务器端ID为:rblTest
var radioButtonListClientID="<%= rblTest.ClientID %>"

//根据RadioButtonList控件的客户端id取被选中的值
//oId 为控件的客户端id
//返回null时为没有选中
function GetRadioButtonListSelectValue(oId) {
var returnValue=null;
var oRadioButtonList=document.getElementById(oId);
var oRadioButtonLists=oRadioButtonList.getElementsByTagName('input');
for(var i=0;i<oRadioButtonLists.length;i++) {
if(oRadioButtonLists[i].type == "radio") {
if(oRadioButtonLists[i].checked) {
returnValue = oRadioButtonLists[i].value;
break;
}
}
}
return returnValue;
}


</script>

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧