[英]How do I trigger a Jquery function with a Drop down list?
我有2個具有OnSelectedIndexChanged屬性的asp:DropdownLists。 觸發該命令后,我想運行一個jquery函數,該函數會讓用戶知道正在處理數據。 如何跳轉到jQuery函數,有沒有一種方法不必使用唯一的ID?
<asp:DropDownList ID="ddlFirst" runat="server" OnSelectedIndexChanged="ddlChange">
<asp:ListItem>All</asp:ListItem>
<asp:ListItem>None</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlSecond" runat="server" OnSelectedIndexChanged="ddlChange">
<asp:ListItem>All</asp:ListItem>
<asp:ListItem>None</asp:ListItem>
</asp:DropDownList>
$(document).ready(function () {
$("???").change(function () {
//code
});
});
給他們上課並使用$('.yourClass')
您的DDL上沒有附加AutoPostBack =“ true”屬性,因此我不知道您打算如何通知用戶。 無論如何
<asp:DropDownList ID="ddlFirst" onchange="myFunc();">
</asp:DropDownList>
function myFunc() {
// insert JS code here
}
使用ASP.net,總是有此選項:
<asp:DropDownList ID="ddlFirst" runat="server" OnSelectedIndexChanged="ddlChange">
<asp:ListItem>All</asp:ListItem>
<asp:ListItem>None</asp:ListItem>
</asp:DropDownList>
$(document).ready(function () {
$("#<%= ddlFirst.ClientID %>").change(function () {
//code
});
});
這會將DDL的ID動態加載到將加載到頁面的javascript中。 我只是將我的JavaScript函數與asp.net代碼放在同一頁面上
首先,分配一個CssClass
<asp:DropDownList ID="ddlFirst" CssClass="myDropDown" runat="server"
OnSelectedIndexChanged="ddlChange">
<asp:ListItem>All</asp:ListItem>
<asp:ListItem>None</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlSecond" CssClass="myDropDown" runat="server"
OnSelectedIndexChanged="ddlChange">
<asp:ListItem>All</asp:ListItem>
<asp:ListItem>None</asp:ListItem>
</asp:DropDownList>
然后,執行以下操作-
$(document).ready(function () {
$(".myDropDown").change(function () {
// code to display user message
});
});
你有嘗試過嗎?
$("select").change(function () {
});
給ddl一個類,然后執行以下操作:
$(document).ready(function () {
$("select.myClassName").change(function () {
//code
});
});
嘿,您可以使用像這樣的東西$(“ select [id $ ='ddlfirst']”)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.