通过CSS和JavaScript隐藏和显示 asp.net 单选按钮

hide and show asp.net radio button via css and javascript

本文关键字:asp net 显示 单选按钮 隐藏 CSS JavaScript 通过      更新时间:2023-09-26

所以我试图根据列表框的选择隐藏和显示一些内容。我在页面加载时使用 css 隐藏一些内容,然后在选择某些内容时显示它。其中大部分都有效,但无法弄清楚为什么这些单选按钮不会显示。

这是单选按钮和标签...

        <br /><!--View/Send By-->
        <asp:Label ID="lblViewSend" runat="server" Text="View/Send as" style="display:none;"></asp:Label>
        <asp:RadioButton ID="rdViewPrint" Text="View/Print" runat="server" OnClick="javascript:disableFields();" GroupName="viewSend" Checked="True" style="display:none; margin-left:10px;" />
        <asp:RadioButton ID="rdEmail" Text="Email" runat="server" OnClick="javascript:emailFields();" GroupName="viewSend" style="display:none; margin-left:10px;" />
        <asp:RadioButton ID="rdFax" Text="Fax" runat="server" OnClick="javascript:faxFields();" GroupName="viewSend" style="display:none; margin-left:10px;" />

在列表框中选择项目时显示它们的 javascript...

function lbSelected() {
             var sel = document.getElementById('<%=lbPatientVisits.ClientID%>');
             var listlength = sel.options.length;
             document.getElementById('<%=lblViewSend.ClientID%>').style.display = "inherit";
             document.getElementById('<%=rdViewPrint.ClientID%>').style.display = "inherit";
             document.getElementById('<%=rdEmail.ClientID%>').style.display = "inherit";
             document.getElementById('<%=rdFax.ClientID%>').style.display = "inherit";
//...plus more code that functions correctly...
    }

标签将按预期显示在页面上,但单选按钮不会。我也尝试了这个作为一点变化,它也没有这样工作......

var rbtn = document.getElementById('<%=rdViewPrint.ClientID%>');
         rbtn.style.display = 'inherit';

我错过或忽略了什么?该代码似乎适用于常规按钮和标签,但不适用于单选框?感谢您的任何帮助。

这是使用 jquery 的完整示例:

<script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#name").click(function () {
            $("#<%=this.myRadio.ClientID %>").toggle();
        });
    });
</script>

    <asp:RadioButtonList runat="server" ID="myRadio">
        <asp:ListItem Text="text1" />
        <asp:ListItem Text="text2" />
    </asp:RadioButtonList>
    <input type="button" id="name" value="click me" />