jQuery提供了两种方式来阻止事件冒泡。

方式一:event.stopPropagation();

$("#div1").mousedown(function (event) {
  event.stopPropagation();
});

方式一:return false;

$("#div1").mousedown(function (event) {
  return false;
});

这两种方式是有区别的。

return false 不仅阻止了事件往上冒泡,而且阻止了事件本身。

event.stopPropagation() 则只阻止事件往上冒泡,不阻止事件本身。

 

相关文章:

  • 2021-08-14
  • 2021-12-17
  • 2021-12-17
  • 2021-12-17
  • 2021-10-03
  • 2022-12-23
猜你喜欢
  • 2021-05-24
  • 2022-12-23
  • 2021-10-22
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
相关资源
相似解决方案