0

我正在使用一个 Webforms 页面,我在其中添加了一个简单的 YES/NO 单选按钮。我创建了一个查询单选按钮的 JavaScript 函数,它适用于 Chrome,但适用于 IE8(企业标准浏览器)。我很困惑试图想出一种方法来查看使用 IE8 运行时单击了哪个按钮。这是 HTML 页面中的按钮:

<td width="35%">
    <label class="label_bold floatLeft" style="margin-top: .25em">Clinicals sent:</label>
 </td>
<td width="15%">       
    <asp:RadioButtonList ID="rbtClinicalsSent" 
                         AutoPostBack="true" 
                         RepeatLayout="Flow" 
                         RepeatDirection="Horizontal"
                         OnClick="rbtClinicalsSent_clicked()"
                         OnTextChanged="rbtClinicalsSent_TextChanged" 
                         runat="server">
        <asp:ListItem Value="1">Yes</asp:ListItem>
        <asp:ListItem Value="0">No</asp:ListItem>
    </asp:RadioButtonList>
</td>

我的 JavaScript 函数(从 StackOverflow 上的其他地方复制)在 Chrome 上运行良好(没有尝试过 Firefox)。

function rbtClinicalsSent_clicked() {
    /* This is based on the assumption that the first element
       in the radio button is Yes */
    var yesButtonClicked = false;
    var radioButton;
    radioButton = document.getElementsByName("rbtClinicalsSent");
    for (i= 0; i< radioButton.length; i++){ 
        if (radioButton[i].checked & rbtIdx===0) 
            yesButtonClicked = true;
    };
    return yesButtonClicked;
};

当我使用 IE8 运行调试器并查看可用于“rbtClinicalsSent”单选按钮的方法时,似乎没有任何可用于预先检查“已单击”状态的方法。我认为一个理想的解决方案是转储 IE8,这在这种企业环境中是不可能的。

TIA 斯科特

4

1 回答 1

0

我找到了答案。在 IE8中,radioButton[0]包含一些元数据,但不是选中的属性。可能有点有用的属性是innerText,对于说“是”和“否”的两个单选按钮,innerText 是“是”。修复方法是检查“typeof(RadioButton[i])==="undefined"。下面是适用于 IE8、Chrome 和 Firefox 的相同函数。

function rbtClinicalsSentYes_clicked() {
/* This is based on the assumption that the first element
   in the radio button is Yes */
var yesButtonClicked = false;
var radioButton;
radioButton = document.getElementsByName("rbtClinicalsSent");
for (i= 0; i< radioButton.length; i++){ 
    if (typeof(radioButton[i].checked) === "undefined") {
        continue;
    }
    if (radioButton[i].checked & rbtIdx===0) 
        yesButtonClicked = true;
};
return yesButtonClicked;

};

于 2013-10-05T05:03:25.287 回答