jQuery的我怎么用Ajax加载的内容互动?互动、加载、我怎么、内容

2023-09-11 01:34:32 作者:初恋迈进老树

我成功地通过使用

jQuery(".menu li a").click( function(event){

    jQuery("#loadingArea").load(this.href)

});

被加载的内容

之后,我在我的网页新元素。我曾尝试申请jQuery的操作(做什么,当我点击或悬停鼠标),和要素没有响应。

After the content is loaded, I have new elements in my page. I have tried to apply jQuery manipulation (do something when I click or hover the mouse), and the element does not respond.

请给我解释一下为什么我无法触发已通过AJAX加载内容的事件?

Please explain to me why I am unable to trigger events in content that has been loaded through ajax?

请问方法.load()有事情做与此(即,如果我用$就我将能够与这些内容进行交互)?

Does the method .load() has something to do with this (i.e. if I had used $.ajax I would be able to interact with such content)?

感谢您,

推荐答案

.live()的回答你的问题:

http://api.jquery.com/live/

从文档:

的.live()方法能够影响尚未被元件   处理程序绑定:通过使用事件代表团加入到DOM   祖代元素负责所触发的事件   它的后代。传递给.live处理程序()永远不会绑定到一个   元件;相反,.live()绑定一个特殊的处理程序的根   DOM树。

The .live() method is able to affect elements that have not yet been added to the DOM through the use of event delegation: a handler bound to an ancestor element is responsible for events that are triggered on its descendants. The handler passed to .live() is never bound to an element; instead, .live() binds a special handler to the root of the DOM tree.