提问人:BrokenCode 提问时间:4/3/2021 最后编辑:showdevBrokenCode 更新时间:4/3/2021 访问量:220
防止 click() 事件冒泡 dom
Prevent click() event from bubbling up the dom
问:
我该如何重写它以防止事件冒泡 dom 并触发其他函数?click()
wallcarousel.on('select.flickity', function() {
$('.filter-category.is-selected a').click();
});
我试着这样添加:e.stopPropagation();
wallcarousel.on('select.flickity', function() {
$('.filter-category.is-selected a').click();
e.stopPropagation(); //this did not work
});
答:
3赞
Sergey Sklyar
4/3/2021
#1
这应该可以解决问题:
wallcarousel.on('select.flickity', function() {
$('.filter-category.is-selected a').click(function(event) {
event.stopPropagation();
});
});
或 ES6 版本:
wallcarousel.on(
'select.flickity',
() => $('.filter-category.is-selected a')
.click(event => event.stopPropagation());
);
评论
e
e
click()
stopPropagation()
click
function(e)
.click(e)
e