您可以使用与简单 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);">