javascript event.stopPropagation() 不适用于 jQuery 1.7 的 chrome
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8021846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
event.stopPropagation() not working in chrome with jQuery 1.7
提问by Craig
For some reason clicking the document isn't working in Chrome (the closeQuickView is not being called).
出于某种原因,单击文档在 Chrome 中不起作用(未调用 closeQuickView)。
The elements are loaded via AJAX and so need to have .on() action (previously .live() which is now deprecated in jQuery 1.7)
元素是通过 AJAX 加载的,因此需要有 .on() 操作(以前是 .live() ,现在在jQuery 1.7 中已弃用)
Used the example given here: How do I detect a click outside an element?as a basis
使用此处给出的示例:如何检测元素外的点击?作为基础
$('html').on('click', '.poster:not(.active) .image-effect', function (event) {
var obj = $(this).parent();
// If there are no .close spans
if (obj.find('.close').length === 0) {
// Add the close element by javascript to remain semantic
obj.find('.quick-view').append('<span class="close">×</span>');
}
// Close any open Quick Views
closeQuickView();
// Add the active class (controls opacity)
obj.addClass('active');
// Fade in the Quick View
obj.find('.quick-view').fadeIn(200, 'easeInOutQuint');
event.preventDefault();
event.stopPropagation();
});
$('html').on('click', '.active', function () {
return false;
});
$('html').on('click', '.close', function () {
closeQuickView();
});
$('html').on('click', '.quick-view', function (event) {
event.stopPropagation();
});
// Close the QuickView with a button
$('html').on('click', function () {
closeQuickView();
});
function closeQuickView() {
$('.poster').removeClass('active');
$('.quick-view').fadeOut(200, 'easeInOutQuint');
}
My markup is as follows:
我的标记如下:
<figure class="grid_2 box poster">
<a class="image-effect" href="#">
<img class="colour" src="path/to/image" />
<img class="bw" src="path/to/image" />
</a>
<div class="quick-view">
Content
</div>
</figure>
回答by Sam
回答by giop
jquery 1.6.4 suffer the same bug. Resolved using stopImmediatePropagation.
jquery 1.6.4 遭受同样的错误。使用 stopImmediatePropagation 解决。