为什么我的 livequery 附加函数会针对页面上的所有内容触发?
我在页面上的图像上附加了一个鼠标悬停功能和相反的鼠标悬停功能,以便在将鼠标悬停在图像上时显示更大的版本。这些函数通过 livequery 附加到图像元素。
问题是,我的函数似乎已附加到页面上的每个元素,而不仅仅是我希望它们附加到的图像。如果我将 console.log
放入函数中,每当我将鼠标移入或移出页面上的任何元素时,我都会看到它打印出来。
你知道为什么 livequery 会绑定到这么多东西吗?
代码如下:
Assets.registerPopups = function(selector, context) {
var targets = jQuery(selector, context);
targets.livequery("mouseover", function(e) {
console.log("mouseover e.target", e.target);
});
targets.livequery("mouseout", function(e) {
console.log("mouseout e.target", e.target);
});
};
jQuery(function(){
Assets.registerPopups(".photo, .video, .flash, .h264", "#controller.project_assets.index")
});
注意:这是我继承的一个维护不善的项目,因此我正在处理 jQuery 1.2.6 和 livequery 1.0.2。我正在尝试升级它。
I have a mouseover function and opposite mouseout function attached to images on my page to bring up a larger version when they're hovered over. The functions are attached to the image elements via livequery.
The problem is that it appears my functions have been attached to every element on the page, not just the images I want them to be attached to. If I put a console.log
into the function I'll see it print any time I mouse in or out of any element on the page.
Any ideas why livequery is binding to so many things?
Here's the code:
Assets.registerPopups = function(selector, context) {
var targets = jQuery(selector, context);
targets.livequery("mouseover", function(e) {
console.log("mouseover e.target", e.target);
});
targets.livequery("mouseout", function(e) {
console.log("mouseout e.target", e.target);
});
};
jQuery(function(){
Assets.registerPopups(".photo, .video, .flash, .h264", "#controller.project_assets.index")
});
Note: This is a poorly maintained project I inherited so I'm dealing with jQuery 1.2.6 and livequery 1.0.2. I'm in the process of trying to upgrade it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论