Page_load里RadioButtonList1绑定后,添加下面代码
foreach (ListItem item in RadioButtonList1.Items)
{
item.Attributes.Add("onclick", "getVal('" + item.Value + "','" + item.Text + "')");
}
前台获的
function getVal(itemValue,itemText){
alert(itemValue);//获得选择的value
alert(itemText);}
foreach (ListItem item in RadioButtonList1.Items)
{
item.Attributes.Add("onclick", "getVal('" + item.Value + "','" + item.Text + "')");
}
前台获的
function getVal(itemValue,itemText){
alert(itemValue);//获得选择的value
alert(itemText);}
解决方案 »
- Js 调用VC函数,VC函数是有参数的,该怎么传递
- js跨域操作窗口出错误的问题
- jQuery新旧版本兼容问题
- iframe的一个怪问题
- 关于参数完整性验证的问题
- var strContent = $(":checkbox, :radio ").serlize()的语法
- appendChild 对<iframe>操作时,参数错误,在线等!
- window.close()方法在netscapse中好像失效了?求救啊!!!
- 经常有网站修改IE主页设置,谁能写个javascript代码恢复主页设置?
- 一个小问题 20分相送
- setTimeout 问题
- revealTrans滤镜在哪些浏览器中被支持?除了Flash,还有什么可以替代?
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
</asp:RadioButtonList><script language="javascript">
function getSelectRadio()
{
var o = {};
var radiolist = document.getElementById("RadioButtonList1");
for(var i=0;i<radiolist.rows.length;i++){
var radio = radiolist.rows[0].cells[0].childNodes[0];
if(radio.checked){
o.value = radio.value;
o.text = radiolist.rows[0].cells[0].childNodes[1].innerText;
break;
}
}
alert(o.value);
alert(o.text);
}
</script>
var radiolist = document.getElementById("<%=RadioButtonList1.ClientID %>");
<label for="RadioButtonList_0">name1</label>
<input id="RadioButtonList_1" type="radio" name="RadioButtonList" value="2" />
<label for="RadioButtonList_1">name2</label>
<input id="RadioButtonList_2" type="radio" name="RadioButtonList" value="3" />
<label for="RadioButtonList_2">name3</label>
<input id="RadioButtonList_3" type="radio" name="RadioButtonList" value="4" />
<label for="RadioButtonList_3">name4</label> var radiolist = document.getElementById("RadioButtonList1") ;radiolist 就等于null 了,怎么解决呢?
RadioButtonList1是<asp:RadioButtonList的ID,不是里面每个radio的ID
alert(" <%=RadioButtonList1.ClientID %>“) 时,正常显示RadioButtonList1 ;
但var radiolist = document.getElementById(" <%=RadioButtonList1.ClientID %>");
alert(radiolist) 时,就是null 。麻烦CutBug了 。
你页面没有载入,alert当然是null
RepeatLayout="Flow" runat="server" RepeatColumns="3" onclick="setTextBox()"></asp:RadioButtonList><script language="javascript">function setTextBox()
{
alert('<%=rblGenerationScene.ClientID%>');
var radiolist = document.getElementById('<%=rblGenerationScene.ClientID%>');
alert(radiolist);
}</script>
RepeatDirection="Horizontal">
<asp:ListItem>111111</asp:ListItem>
<asp:ListItem>2222</asp:ListItem>
<asp:ListItem>33333</asp:ListItem>
<asp:ListItem>4444</asp:ListItem>
<asp:ListItem>555555</asp:ListItem>
<asp:ListItem>666666666</asp:ListItem>
</asp:radiobuttonlist>
<script type="text/javascript">
var radioButtonListArray = document.getElementsByName("Radiobuttonlist1");
for (var i = 0; i < radioButtonListArray.length; i++) {
if ((radioButtonListArray[i].type != "undefined") && (radioButtonListArray[i].type == "radio")) {
radioButtonListArray[i].onclick = function() {
alert("value值:" + this.value + "\r\n" + "text值:" + this.nextSibling.innerHTML);
}
}
}
</script>