0

我正在尝试根据另一个单选按钮选择的答案禁用或启用单选按钮列表,这是我放在一起但未能成功使其工作的代码:

<script type="text/javascript">
        // enable May we contact your present employer if Employed Now is yes

        function EmployedNowYes(answer) {

            if (answer == "Yes") {
                document.getElementById("<%=ContactEmployer.ClientID %>").enabled = true;
            }

            if (answer == "No") {
                document.getElementById("<%=ContactEmployer.ClientID %>").enabled = false;
            }

        }

    </script>
Are you employed now?
                <asp:RadioButtonList ID="EmployedNow" runat="server" RepeatDirection="Horizontal" >
                    <asp:ListItem Value="Yes" onclick ="EmployedNowYes(this.value)">Yes</asp:ListItem>
                    <asp:ListItem Value="No" onclick ="EmployedNowYes(this.value)">No</asp:ListItem>
                </asp:RadioButtonList>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" ControlToValidate="EmployedNow"
                    ErrorMessage="* Required field." ForeColor="Red"> </asp:RequiredFieldValidator>
            </td><td class="style42" valign="top">
                May we contact your present employer:
                <asp:RadioButtonList ID="ContactEmployer" runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem >Yes</asp:ListItem>
                    <asp:ListItem >No</asp:ListItem>
                </asp:RadioButtonList>
                            </td>
4

1 回答 1

0

我发现在Javascript中你需要写......

document.getElementById("<%=ContactEmployer.ClientID %>").disabled = false;
document.getElementById("<%=ContactEmployer.ClientID %>").disabled = true;

您可能还会发现已禁用控件的值不会在回发中返回给代码隐藏。

于 2013-01-18T08:40:42.667 回答