jQuery函数不能从父级继承

jQuery function to not inherit from parent

本文关键字:继承 函数 不能 jQuery      更新时间:2023-09-26

我有很多嵌套的div:

<div id="container_anatomy">
        <div id = "container_anatomy_painted">
             <div id="example"> Item1</div>
             <div id="example"> Item2</div>
             <div id="example"> Item3</div>
        </div>
</div>

我只想用这个函数使外部div "anatomy_part""container_anatomy_painted"可以拖动:

var clicked = false,
  clickX;
$('#container_anatomy_painted').on({
  'mousemove': function(e) {
    clicked && updateScrollPos(e);
  },
  'mousedown': function(e) {
    clicked = true;
    clickX = e.pageX;
    clickY = e.pageY;
    last_x = $('#container_wrapper_anatomy').scrollLeft();
    last_y = $('#container_wrapper_anatomy').scrollTop();
    event.preventDefault();
  },
});

但现在,即使是"榜样"——物品也是可以移动的。有没有办法不让嵌套的div继承相同的jquery函数?所以我只能在"container_anatomy_painted"上使用"mousemove"

您可以绑定到子div,并在该绑定中使用event.stopPropagation();