RadioButtonList被编译以后成了数个RadioButtonList1_1(2,3....)之类的怪胎,有没有办法用js实现获得RadioButtonList的index的值?我的意思是能不能在客户端通过分析RadioButtonList1_1的名称及状态来得知那个被选中?
解决方案 »
- 浏览器软件制作?
- Winfrom项目,服务器客户端之间的文件传递
- UpdatePanel中弹出提示框后怎么跳转到新页面?
- 高分求解﹕為何在TextBox控件(設置MultiLine=true)﹐提交表單時﹐這個文本框中的內容﹕換行符沒了??
- 如何跨站点用户登陆问题!
- visual studio 2005使用中遇到的问题求解
- 散分了。。顶者有分。。。。。一个很简单,但很实用的问题。。。。
- 请教个问题, 谢谢!
- 请各位大虾帮我看看这个报错是什么意思?
- 请问,.net里面得服务器端控件是不是相当于jsp在服务器端运行得java小程序??
- 大家帮我!
- DataGrid的PageSelectChanged事件与ItemCommand事件
-------------------------
在HTML中:
-------------------------
<form id="Form1" method="post" runat="server">
<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem Value="item1">item1</asp:ListItem>
<asp:ListItem Value="item2">item2</asp:ListItem>
<asp:ListItem Value="item3">item3</asp:ListItem>
</asp:RadioButtonList><INPUT type="button" value="Button" onclick="chk()">
</form>
------------------
在<head></head>之间加上以下这段函数:
------------------
function chk()
{
var ary=document.all.tags("input");
for(var i=0;i<ary.length;i++)
{
if(ary[i].type=="radio")
{
if(ary[i].checked==true)
{
alert(ary[i].value);
}
}
}
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Temp</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<form name="Form1" method="post" action="temp.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE" value="dDwtMTc2MTIzNDA0Njs7Pg==" /> <FONT face="宋体"> </FONT>
<table id="RadioButtonList1" border="0">
<tr>
<td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="radio1" /><label for="RadioButtonList1_0">radio1</label></td>
</tr><tr>
<td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="radio2" /><label for="RadioButtonList1_1">radio2</label></td>
</tr><tr>
<td><input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="radio3" /><label for="RadioButtonList1_2">radio3</label></td>
</tr><tr>
<td><input id="RadioButtonList1_3" type="radio" name="RadioButtonList1" value="radio4" /><label for="RadioButtonList1_3">radio4</label></td>
</tr><tr>
<td><input id="RadioButtonList1_4" type="radio" name="RadioButtonList1" value="radio5" /><label for="RadioButtonList1_4">radio5</label></td>
</tr><tr>
<td><input id="RadioButtonList1_5" type="radio" name="RadioButtonList1" value="radio6" /><label for="RadioButtonList1_5">radio6</label></td>
</tr><tr>
<td><input id="RadioButtonList1_6" type="radio" name="RadioButtonList1" value="radio7" /><label for="RadioButtonList1_6">radio7</label></td>
</tr><tr>
<td><input id="RadioButtonList1_7" type="radio" name="RadioButtonList1" value="radio8" /><label for="RadioButtonList1_7">radio8</label></td>
</tr><tr>
<td><input id="RadioButtonList1_8" type="radio" name="RadioButtonList1" value="radio9" /><label for="RadioButtonList1_8">radio9</label></td>
</tr>
</table></form>
<script>
function getIndex(obj)
{
obj = document.getElementById("RadioButtonList1");
var n = -1;
var txt = null;
for(i=0;i<obj.rows.length;i++)
{
var r = document.getElementById(obj.id + "_" + i);
if(r.checked)
{
n = i;
txt = r.value;
}
}
if(n!=-1)
alert(txt + " 被选中了!");
}
</script>
<INPUT type="button" value="Button" onclick="getIndex('RadioButtonList1');">
</body>
</HTML>
{
var i = 1;
while(document.all[RadioButtonListID+'_'+i] != null)
{
if(document.all[RadioButtonListID+'_'+i].checked == true)
return i;
i++;
}
return 0;
}use like this :var ckindex = getckindex("RadioButtonList1");