使用 livequery:找不到通过 ajax 创建的传播元素
我正在使用 jQuery 1.3.2 和 Live Query 插件。该脚本需要在 FF 和 IE6 中运行。升级 jQuery 并使用 live 是不可能的。
不知何故,动态创建的元素不会调用此脚本。
$('select').livequery('change',function(){
var select_id = $(this).attr("id"); ...
...
...
});
$('select').livequery('mouseover',hideExtensions());
function hideExtensions(){
...
...
}
在 IE6 和 FF 中,静态(已存在)元素可以正确调用该函数。但是,动态创建的元素不会调用它。
可能是什么原因?
更新 我用“live”测试了相同的功能。它在 FF 中有效,但在 IE6 中不起作用,当然不是......这就是为什么我正在寻找 livequery 的解决方法。
I'm using jQuery 1.3.2 and Live Query plugin. The script needs to work in FF as well as IE6. Upgrading jQuery and using live instead isn't a possibility.
Somehow this script won't be called by the dynamically created element.
$('select').livequery('change',function(){
var select_id = $(this).attr("id"); ...
...
...
});
$('select').livequery('mouseover',hideExtensions());
function hideExtensions(){
...
...
}
In both IE6 and FF, the function is correctly called by the static (already existing) elements. However, it's not being called by the dynamically created element.
What could be the reason?
Update
I tested the same function with "live". It worked in FF, but not in IE6, of course not... That's why i'm looking for a workaround with livequery.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是否有原因无法升级到 jQuery 1.4.2 并使用内置的
live
回调?如果 livequery 不起作用,您可以尝试的另一种选择是使用一些核心 JavaScript 进行一些“手动”事件委托,并依赖于事件冒泡到直接父级。假设您有一个如下所示的 DOM 结构:
在您的 JavaScript 中:
Is there a reason you can't upgrade to jQuery 1.4.2 and use the built-in
live
callback there?If livequery isn't working, an alternative you can try is some "manual" event delegation with some core JavaScript, and rely on event bubbling to an immediate parent. Let's say you had a DOM structure like this:
And in your JavaScript: