[英]My jquery selectors doesn't work after update panel in content page
我有一個內容頁面,我在asp:updatepanel之后寫了一些jquery選擇器,這是第一次,當頁面加載$(document).ready(function()可以正常工作,但是回發后,選擇器不再起作用了,任何方式都存在解決這個問題?
<asp:content id="Content1" contentplaceholderid="contentplaceholder1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtdate" runat="server" CssClass="persianDTP" ></asp:TextBox>
<!-- some code -->
</ContentTemplate>
</asp:UpdatePanel>
<script>
$(document).ready(function () {
$('.PersianDTP').datepicker({
showOn: 'button',
buttonImage: 'calendar.png',
dateFormat: 'yy/mm/dd',
//appendText: ' (yy/mm/dd)',
changeMonth: true,
changeYear: true,
//selectOtherMonths: true,
//showOtherMonths: true,
showStatus: true,
showButtonPanel: true,
buttonImageOnly: true,
buttonText: 'Choose a Date',
onClose: function () {
this.focus();
}
});
jQuery(function ($) {
$(".PersianDTP").mask("9999/99/99");
});
});
</script>
</asp:content>
所有JQuery插件都應用於HTML頁面的Page Load事件,或者換句話說就是文檔就緒事件,當整個頁面或文檔完全在瀏覽器中呈現時將觸發該事件。 jQuery分配的內容丟失,因此該插件停止工作,您可以在UpdatePanel的異步請求或部分回發完成時重新應用jQuery插件:您需要在回發時重新創建Jquery代碼。
示例代碼:)
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script type="text/javascript">
$(document).ready(function () {
$(<%=lstBoxTest.ClientID%>).SumoSelect({ selectAll: true });
});
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
//Binding Code Again
$(<%=lstBoxTest.ClientID%>).SumoSelect({ selectAll: true });
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.