问题描述
我有asp.net页面异步回发后用jQuery事件处理的一个问题。
我读 - 这是一个很好的解决方案,但我需要一个单独的函数。
所以我使用。
I Have a problem with jquery event handler after async postback on asp.net page.I read this topic - it's a good solution, but I need a separate function.So I'm using jquery masked plugin.
我的js code现在是:
My js code now is:
<script type="text/javascript">
jQuery(document).ready(function () {
var control = $("#txtCustomerPhone");
InitPhonePattern(this, control);
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(InitPhonePattern(this, control));
});
function InitPhonePattern(sender, args) {
$(args[0]).mask("+7 (999) 999-99-99", { completed:
function () {
$('#btnCheckCustomerPhone').click();}
});
}
</script>
正如你看到面罩被初始化2次:在文档就绪()和异步回发后(上endRequest())。但是面膜插件没有异步回发后映射。
As you see mask was initialized 2 times: on document Ready() and after async postback (on endRequest()). But mask plugin is not mapped after async postback.
有人了解的问题吗?我会帮忙不胜感激!
Someone understands problem? I would be grateful for help!
推荐答案
我要这么说感谢求助和正确的方向!
在您的code我只固定字符串:
I want so say thanks to Aristos for help and right direction!In your code I fixed only this string:
jQuery(document).ready(Init);//direct transfer function not work;
所以最终code是这样的:
So final code looks like this:
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(EndRequest);
function EndRequest(sender, args) {
Init();
}
$(document).ready(function () {
Init();
});
function Init() {
var control = $('#txtCustomerPhone');
InitPhonePattern(control);
}
function InitPhonePattern(args) {
$(args).mask("+7 (999) 999-99-99", { completed:
function () {
$('#btnCheckCustomerPhone').click();
}
});
}
</script>
这篇关于UpdatePanel的异步回发后的Javascript事件订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!