父子元素都有拖动功能,如何阻止父元素的事件。

父子元素都有拖拽功能,怎么写才能使父子元素各自的拖拽功能不互相影响。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/1.2.6/jquery.min.js"></script>
</head>

<body>
    <div class="container">
        <div class="bar"></div>
        <div class="poite"></div>
    </div>
    <script>
        $(".container").mousedown(function (event) {
          ...
            $(document.body).mousemove(function (event) {
                ....
            });
        });
        $(".bar").mousedown(function (event) {
          ...
            $(document.body).mousemove(function (event) {
                ....
            });
        });
        $(".poite").mousedown(function (event) {
          ...
            $(document.body).mousemove(function (event) {
                ....
            });
        });
    </script>
</body>

</html>
阅读 5k
1 个回答
event.stopPropagation()

阻止事件冒泡

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题