[英]ASP.NET Server Controls - Show Hide Textbox based on Dropdown selection
[英]ASP.NET Server Controls - Show Hide Textbox based on Dropdown selection
根據用戶從下拉菜單中進行的選擇,顯示/隱藏文本框或整個div部分的最佳方法是什么? 我認為服務器控件無法實現這一點,所以我必須使用常規的客戶端HTML控件,對嗎? 感謝您的任何投入。 jQuery會是最好的選擇嗎?
基於下拉選擇,我希望能夠顯示以下Div,並且默認情況下隱藏Div。 有何想法?:
<div id="divLimitPrice">Limit Price<br />
<asp:TextBox ID="txtLimitPrice" runat="server" ValidationGroup="ValidationGroupOrder"> </asp:TextBox>
您可以使用與簡單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);">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.