Mak*_*hyy 2 .net jquery asp-classic drop-down-menu
我想用ASP .Net触发jQuery更改事件.这是ASP和jQuery代码的一部分:
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="body">
<p>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</p>
<script type ="javascript">
$('#DropDownList1').change(function() {
alert( "Handler for .change() called." );
});
</script>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
试图通过id#body_DropDownList1和#DropDownList1来获取元素.不幸的是,两种情况都没有输出.
如果您检查开发人员工具中的dropdownlist元素,您会注意到该ID实际上不是DropdownList1.Asp根据ID属性生成一个id以防止重复,因此它的呈现方式不同.您不能依赖于复制它生成的那个,因为它可能使用不同的ClientID渲染它.你可以设置一个CssClass来选择:
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="body">
<p>
<asp:DropDownList CssClass="DropdownList1" ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</p>
<script type="text/javascript">
$('.DropdownList1').change(function() {
alert( "Handler for .change() called." );
});
</script>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
您还可以根据ClientID(实际在客户端上呈现的ID)选择元素,如下所示:
$("#<%=DropdownList1.ClientID %>")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15029 次 |
最近记录: |