jQuery:触发器不会在加载有.load()的元素上触发 [英] jQuery: triggers do not fire on elements loaded with .load()
问题描述
我有index.php,并使用jQuery .load()从load.php加载内容。
I have index.php and use jQuery .load() to load content from load.php.
当我在索引中的元素上触发事件时.php,事件发生。在相同的元素上,当加载.load()到index.php中时,事件不会触发!
When I trigger an event on elements that are in the index.php, the event fires. On the same elements, when loaded with .load() into index.php the events do not fire!?
为什么?我做错了吗?
如果我用例如FireBug,这个元素的#id就像它应该是一样的,但是甚至不会有这样的功能:
If I preview the page with e.g. FireBug, the #id of the element is exactly like it should be, but not even a function like this works:
$('#clickme').click(function() {
alert('hello');
});
相同的功能可以工作,如果元素放在index.php中,而不是加载.load ()。任何想法?
The same function works, if the element is placed in the index.php and not loaded with .load(). Any ideas??
提前非常感谢!
推荐答案
单击
事件绑定器不绑定到执行后创建的任何元素。您可以在 .load()
方法之后立即添加单击
监听器,也可以使用类似 live
或 delegate
绑定到DOM中的元素模式。
The click
event binder does not bind to any elements created after execution. You can add a click
listener immediately following the .load()
method, or you can use something like live
or delegate
to bind to element patterns in the DOM.
这篇关于jQuery:触发器不会在加载有.load()的元素上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!