我现在有我的网页上下面的代码:显示面板基于单选按钮上选择(S)
<asp:RadioButtonList id="GroupButtons" CellSpacing="5" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="0" selected="true" />
<asp:ListItem Value="1" />
<asp:ListItem Value="2" />
<asp:ListItem Value="3" />
<asp:ListItem Value="4" />
<asp:ListItem Value="5" />
<asp:ListItem Value="6" />
<asp:ListItem Value="7" />
</asp:RadioButtonList>
<asp:Panel ID="GroupPanel" runat="server">
<b>How can we improve our service?</b><br />
<asp:TextBox ID="GroupTextBox" runat="server" />
</asp:Panel>
此代码也多次在不同部分(IndividualButtons/IndividualPanel,EducationButtons/EducationPanel等)
我试图找出一个很好的解决方案执行以下操作:
- 当单选按钮列表中选定的值是0或5-7,隐藏相关的面板。
- 当所选值为1-4时,显示关联的面板。
- 让此代码适用于所有部分,以避免膨胀(如果可能)。
有什么建议吗?
编辑:下面的代码让我的GroupPanel面板隐藏并显示每次GroupButtons选择更改。但是,我需要它显示1-4,并隐藏0和5-7。
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
var id = '<%= GroupButtons.ClientId %>_0';
$(function() {
var i = 0
$('#<%= GroupButtons.ClientId %> :radio').click(function(){
if ($(this).attr('id') != id) {
$('#<%= GroupPanel.ClientId%>').toggle();
id = $(this).attr('id');
}
});
});
</script>
很好地做了这个诀窍,虽然你在这里和小提琴之间的脚本是不同的(我需要小提琴版本)。谢谢! – niclake 2014-10-02 18:33:40
更新了脚本。 – Vahi 2014-10-02 18:49:06