jQuery的需要重新绑定的部分页面回发事件 [英] jquery needs to rebind events on partial page postback

查看:221
本文介绍了jQuery的需要重新绑定的部分页面回发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能重新绑定我的事件(jQuery的),当我执行部分网页提交?

How can I rebind my events (jquery) when I perform a partial page postback?

我使用的接线一切行动:

I am wiring everything up using:

$(document).ready(function(){};

部分页面回传后,我的事件不会开火。

After a partial page postback, my events are not firing.

推荐答案

您可以挖掘到 PageRequestManager endRequestEvent:

You can either tap into the PageRequestManager endRequestEvent:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(){});

或者如果你想连接控制事件,您可以使用jQuery 现场活动的。

另一种方法是手工做的事件委托。它是活事件是在幕后做什么。附加事件处理程序文件本身,则有条件地执行你的方法,如果事件的发送者是你期待的元素。

Another option is to do the event delegation manually. It is what the "live" event are doing under the covers. Attach the event handler to the document itself, then conditionally execute your method if the sender of the event was element you expect.

$(document).click(function(e){  
    if($(e.target).is(".collapseButton")){  
        $(this).find(".collapsePanel").slideToggle(500);  
    }  
})

这篇关于jQuery的需要重新绑定的部分页面回发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆