2

根据用户从下拉列表中的选择显示/隐藏文本框或整个 div 部分的最佳方法是什么?我不相信它可能与服务器控件一起使用,所以我必须使用常规的客户端 HTML 控件,对吗?感谢您的任何意见。jQuery 会是最好的选择吗?

基于下拉选择,我希望能够显示以下 Div,并默认隐藏 Div。想法?:

 <div id="divLimitPrice">Limit Price<br />
 <asp:TextBox ID="txtLimitPrice" runat="server" ValidationGroup="ValidationGroupOrder">    </asp:TextBox>

4

1 回答 1

0

您可以使用与简单 html 控件相同的服务器控件来执行此操作。您只需正确设置控件的呈现客户端 ID。这是一个示例:(有关我的工作,请参阅代码注释)

function TriggerChange(me)
{
    // get the drop down control
    var cTheDropDown = jQuery("#<%=ddlControl.ClientID%>");

    // find the value of the selected one
    var SelValue = jQuery('option:selected', cTheDropDown).attr('value');

    // now do what you like with it
    if(SelValue == "open")
      jQuery("#divLimitPrice").show();
    else
      jQuery("#divLimitPrice").hide();
}

一个较短的版本

function TriggerChange(me)
{
    // get the selected value from the drop down list
    //  and base on it, show or hide your div
    if(jQuery("#<%=ddlControl.ClientID%>").val() == "open")
      jQuery("#divLimitPrice").show();
    else
      jQuery("#divLimitPrice").hide();
}

在控制上,您将触发器添加为:

<asp:DropDownList ID="ddlControl" runat="server" onchange="TriggerChange(this);">
于 2013-06-04T00:48:13.377 回答