【问题标题】:jQuery UI: Click event is being triggered on resizejQuery UI:调整大小时触发点击事件
【发布时间】:2018-02-24 12:43:32
【问题描述】:

我在一个元素上使用可调整大小的 jQuery Ui。但是调整大小事件正在触发元素本身的单击事件和其父元素的单击事件。我尝试过使用event.stopPropagation(),但它显然不起作用。

这是我的 html 的简单形式:

<div class="parent">
    <div class="child ui-resizable">
        ...
        <div class="ui-resizable-handle ui-resizable-s"></div>
    </div>
</div>

而我的 js 看起来是这样的:

$('.parent').on('click',function(){
   openModal();
});

$('.child').on('click',function(e){
    e.stopPropagation(); // To Prevent the child triggering parent click event.
    openSecondModal();
});

$('.ui-resizable').resizable({
    ghost: true,
    grid: 24,
    handles: "s",
    resize: function (event, ui) {
        event.stopPropagation();
    },
    start: function (event, ui) {
        event.stopPropagation();
    },
    stop: function (event, ui) {
        event.stopPropagation();
    },

})

拖动处理程序正在触发点击事件。 有没有办法阻止点击事件发生?

【问题讨论】:

  • @Stavm 你的意思是将“stopPropagation()”设置为“.ui-resizable”的点击事件吗?我做到了,并且仍然触发了点击事件。
  • @Stavm 我之前已经检查过,但答案并没有解决我的问题。实际上我的布局和嵌套元素更复杂,所以这个问题的答案对我不起作用。

标签: javascript jquery jquery-ui resizable


【解决方案1】:

也许这对你有用:

$('.parent').on('click',function(e){
   if(e.target !== e.currentTarget) return;
   openModal();
});

【讨论】:

    猜你喜欢
    • 2012-07-03
    • 2014-12-26
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-02
    • 1970-01-01
    • 2010-10-14
    相关资源
    最近更新 更多