使用 javascript 的 ASP.net 隐藏面板
我有一个 radioButtonList,其中有 2 个项目。具有“是”值的单选按钮和具有“否”值的单选按钮。
下面有一个面板,我希望在选择“是”单选按钮时使其可见,在选择“否”时隐藏该面板。我最初是使用 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
}
预先感谢,
扎普斯
I have a radioButtonList with 2 items in it. A radiobutton with a "Yes" value and a radionButton with a "No" value.
Below that I have a panel which I want made visible when "Yes" radioButton is selected and hidden when "No" is selected. I had originally implemented this using the AutoPostBack attribute but I want to do it in Javascript so that it doesn't cause a postback. Here's the code. Any help would be greatly appreciated.
<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
}
Thanks in advance,
Zaps
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是我编的一个简单例子:
Here is a quick example I made up:
Raja 你的代码中有一些错误,我刚刚将其删除
Raja There is some bug in your code i just removed it
如果您添加一个类或确定“panel1”的真实 id,您可以使用 jQuery 轻松隐藏它:
或者您不使用 jQuery,使用 div/panel 的 id:
重新显示:
或
If you add a class or determine the real id of "panel1", you can use jQuery to hide it easily:
Or you without using jQuery, using the id of the div/panel:
To redisplay:
Or
试试这个:
希望有帮助。
try this:
Hope it helps.
如果您不介意进行部分回发,您还可以将代码放入
UpdatePanel
中(假设您不想回发,以便整个页面不必经过页面生命周期)。if you don't mind doing a partial postback, you can also throw your code into an
UpdatePanel
(assuming that you don't want to postback so that the entire page doesn't have to go through a page life-cycle).