gpt4 book ai didi

javascript - jQuery 如何在 div 及其所有后代上触摸移动时停止传播

转载 作者:行者123 更新时间:2023-11-30 05:37:35 25 4
gpt4 key购买 nike

抱歉真的不知道怎么说。但是我有一个 div,我希望其中的所有元素都有一个 .stopPropagation。但我想在 click 和触摸事件上执行此操作,例如 touchstart touchend touchmove tap dbltap dragstart dragmove dragend

所以我想我可以这样做:

$('#div1').find('*').bind("click touchstart touchend touchmove tap dbltap dragstart dragmove dragend", function(event){
event.stopPropagation();
});

但我不确定这是否是正确的做法。也许我需要一个 .each()

此外,我从未使用过'*' 来选择全部,所以我不确定它是否应该是我拥有的方式还是应该是.find (*) 没有单引号。

谢谢!

最佳答案

没有必要使用 .find('*'),如果你想停止从 div1 的传播 - 如果事件发生在后代中它会传播到 div1 然后会停在那里

$('#div1').on("click touchstart touchend touchmove tap dbltap dragstart dragmove dragend", function (event) {
event.stopPropagation();
});

关于javascript - jQuery 如何在 div 及其所有后代上触摸移动时停止传播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22728414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com