3

我有一个带有 2 个项目的 radioButtonList。具有“是”值的单选按钮和具有“否”值的单选按钮。

下面我有一个面板,我想要在选择“否”时选择并隐藏“是”radiobutton时可见的面板。我最初是使用 AutoPostBack 属性实现的,但我想在 Javascript 中执行它,这样它就不会导致回发。这是代码。任何帮助将不胜感激。

<asp:RadioButtonList ID="rbl1" runat="server" onClick="changed(this);" >
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>

<asp:Panel ID="panel1" runat="server">
<--other controls here -->
</asp:Panel>

function changed(rbl) {
        //not sure what to put in here
    }

提前致谢,

电击

4

5 回答 5

3

这是我编写的一个简单示例:

<!-- Used grouped radio buttons instead of the RadioButtonList as it is harder to deal with -->
<asp:RadioButton ID="rbYes" runat="server" Text="Yes" GroupName="YourGroupName" Checked="true" />
<asp:RadioButton ID="rbNo" runat="server" Text="No" GroupName="YourGroupName" />        
<br /><br />    
<!-- Use a div instead of a panel.  Panels are just glorified divs. -->
<div id="divTest">
    This is a test
</div>

<script type="text/javascript">
    $(document).ready(function()
    {
        $('#<%= rbYes.ClientID %>').click(function() { $('#divTest').show(); });
        $('#<%= rbNo.ClientID %>').click(function() { $('#divTest').hide(); });

    });
</script>
于 2010-03-12T18:52:26.530 回答
1

    function OnclickPanelHide() {
        if (this.value == "No") {
            document.getElementByID('<%=panel1.ClientID%>').style.display = "none";
        }
        else {
            document.getElementByID('<%=panel1.ClientID%>').style.display = "block";
        }
    }


</script>

Raja 您的代码中有一些错误,我刚刚删除了它

于 2014-02-06T05:38:38.247 回答
0

如果你添加一个类或确定“panel1”的真实id,你可以使用jQuery轻松隐藏它:

$('idOfPanel').hide();

或者你不使用 jQuery,使用 div/panel 的 id:

idOfPanel.style.display = "none";

重新显示:

$('idOfPanel').show();

或者

idOfPanel.style.display = "block";
于 2010-03-12T15:16:02.350 回答
0

试试这个:

if (this.value == "No")
{
document.getElementByID('<%=panel1.ClientId%').style.display = "none";
}
else
{
document.getElementByID('<%=panel1.ClientId%').style.display = "block";
}

希望能帮助到你。

于 2010-03-12T19:09:19.460 回答
0

如果您不介意进行部分回发,您也可以将代码放入一个UpdatePanel(假设您不想回发,以便整个页面不必经历页面生命周期)。

于 2010-03-12T19:16:21.397 回答