1

我有以下单选按钮列表:

<asp:Panel ID="pnl_select_sign" runat="server" Visible="false" Style="text-align: right">
        <asp:RadioButtonList ID="rb_select_sign" runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
            OnSelectedIndexChanged="rb_select_sign_SelectedIndexChanged" CausesValidation="false"
            AppendDataBoundItems="true">
            <asp:ListItem Selected="True" Value="0">Normal</asp:ListItem>
            <asp:ListItem Value="1">Electronic</asp:ListItem>
        </asp:RadioButtonList>
    </asp:Panel>

我想css换房overflow-y

overflow-y :auto; 到overflow-y :hidden;

对于 divid = wrap_form

如果我选择了ListItem with Value = 1


萤火虫

<td>
<input id="ctl00_ContentPlaceHolder1_rb_select_sign_0" type="radio" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$rb_select_sign$0\',\'\')', 0)" value="0" name="ctl00$ContentPlaceHolder1$rb_select_sign">
<label for="ctl00_ContentPlaceHolder1_rb_select_sign_0">Normal</label>
</td>
<td>
<input id="ctl00_ContentPlaceHolder1_rb_select_sign_1" type="radio" checked="checked" value="1" name="ctl00$ContentPlaceHolder1$rb_select_sign">
<label for="ctl00_ContentPlaceHolder1_rb_select_sign_1">Electronic</label>
</td>
4

2 回答 2

1

像这样的东西应该工作:

$('input[id^="ctl00_"]').click(function() {
 if ($(this).val() == 1) {
  $('#wrap_form').css('overflow-y', 'hidden');
 }
})

这是jsfiddle

于 2013-01-06T11:32:03.537 回答
1

请注意,如果您使用建议的 javascript 答案,则 css 将在页面回发后恢复正常。您已经在 Your 上使用了回发RadioButtonList,所以我想您可以改为更改服务器端的样式。

更新

将其放入您的方法处理列表中的项目选择更改中:

protected void rb_select_sign_SelectedIndexChanged(object sender, EventArgs e)
{
    if (rb_select_sign.SelectedValue == "1")
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "styleChangeScript", "<script type='text/javascript'>var divToChange = document.getElementById('wrap_form'); if(divToChange) { divToChange.style.overflowY = 'hidden' }</script>", false);
    }
    //the rest of the original code of this method should be here
    //...
}

为了在单击其他按钮等导致回发时使其工作,您应该在Page_Load您的页面事件中放置相同的代码行(或者将其放在单独的方法中并从两个地方调用它)。

于 2013-01-06T11:48:09.243 回答