【问题标题】:hide and show asp.net radio button via css and javascript通过 css 和 javascript 隐藏和显示 asp.net 单选按钮
【发布时间】:2012-07-02 21:22:41
【问题描述】:

所以我试图根据列表框的选择隐藏和显示一些内容。我在页面加载时使用 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';

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

【问题讨论】:

  • 基本的 $("#yourId").hide() / $("#yourId").show() 对你不起作用吗?
  • 我不认为他在使用 jQuery。
  • Hanlet 是正确的,没有使用 jQuery。
  • 试试为单选按钮设置RepeatLayout="Flow"

标签: javascript asp.net css


【解决方案1】:

这是一个使用 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" />

【讨论】:

  • 我目前没有,也没有兴趣在这个时间点添加 jQuery。
猜你喜欢
  • 1970-01-01
  • 2011-03-05
  • 1970-01-01
  • 1970-01-01
  • 2017-04-28
  • 2010-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多