你如何让jQuery的事件绑定到通过Ajax加载的内容是什么? [英] How do you make jQuery bind events to elements loaded via Ajax?

查看:116
本文介绍了你如何让jQuery的事件绑定到通过Ajax加载的内容是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用.load()函数来加载HTML的一个部分,也可以是绑定到某一类一些jQuery功能。 = /

I'm using the .load() function to load a section of html that has some jQuery functionality that is bound to a certain class. =/

想法?

推荐答案

使用的现场活动:

$('.className').live(function(event) {
   ...
}

jQuery的保留了所有的现场选择在这种情况下,一个存储库,如 .className 。和它增加了一个处理程序,以文件为监听事件冒泡到文档。这个特殊的处理器则基本上在所有的现场选择运行,将事件转发到那些符合现场选择的元素,如果有的话。

jQuery keeps a repository of all live selectors such as .className in this case. And it adds a handler to the document to listen for events that bubble up to the document. This special handler then basically runs through all the live selectors and forwards the event to those elements that match the live selectors, if any.

如果任何中间事件处理程序拦截事件之前到达了该文件的进一步传播停止,在生活的处理程序将不会被执行。

If any of the intermediate event handlers intercept the event and stop it from further propagating before it reaches up to the document, the live handlers will not be executed.

这篇关于你如何让jQuery的事件绑定到通过Ajax加载的内容是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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