我在我的网络应用程序中有一个radiobuttonlist我有一个事件onclick为此它在IE中工作正常,但在其他一些浏览器中没有。示例代码如下
<asp:RadioButtonList ID="rbgThreadStatus" runat="server" RepeatDirection="Horizontal"
OnSelectedIndexChanged="rbgThreadStatus_SelectedIndexChanged" onclick="return rdblst_onClick();"
AutoPostBack="True">
<asp:ListItem Selected="True" Value="0">Alpha</asp:ListItem>
<asp:ListItem Value="1">Bravo</asp:ListItem>
<asp:ListItem Value="2">Charlie</asp:ListItem>
<asp:ListItem Value="3">Delta Tickets</asp:ListItem>
<asp:ListItem Value="4">Echo</asp:ListItem>
</asp:RadioButtonList>
<input type="hidden" value="0" id="hdnValue" runat="server" />
以下是Javascript
function rdblst_onClick()
{
var hdnValue = document.getElementById('ctl00_ctl00_MainMaster_ContentPlaceHolder2_hdnValue');
var length = document.getElementById('ctl00_ctl00_MainMaster_ContentPlaceHolder2_rbgThreadStatus').cells.length;
for (var i = 0; i < length; i++)
{
if (document.getElementById('ctl00_ctl00_MainMaster_ContentPlaceHolder2_rbgThreadStatus_' + i.toString()).checked)
{
if (hdnValue.value != document.getElementById('ctl00_ctl00_MainMaster_ContentPlaceHolder2_rbgThreadStatus_' + i.toString()).value)
{
hdnValue.value = document.getElementById('ctl00_ctl00_MainMaster_ContentPlaceHolder2_rbgThreadStatus_' + i.toString()).value;
//Some code here
}
}
}
}
答案 0 :(得分:0)
这是一个Javascript更改。它适用于所有浏览器。
function GetFormObject(objname) {
var obj;
for (i = 0; i < document.forms[0].length; i++) {
obj = document.forms[0].elements[i];
if (obj.id.indexOf(objname) != -1) {
break;
}
}
return obj;
}
function rdblst_onClick() {
var hdnValue = GetFormObject('hdnValue');
var length = GetFormObject('rbgThreadStatus').parentNode.parentNode.cells.length;
for (var i = 0; i < length; i++) {
if (GetFormObject('rbgThreadStatus_' + i.toString()).checked) {
if (hdnValue.value != GetFormObject('rbgThreadStatus_' + i.toString()).value) {
hdnValue.value = GetFormObject('rbgThreadStatus_' + i.toString()).value;
//Some code here
}
}
}
}
答案 1 :(得分:0)
找到解决方案
var length = document.getElementById('ctl00_ctl00_MainMaster_ContentPlaceHolder2_rbgThreadStatus').rows[0].cells.length;