繁体   English   中英

jQuery UI:单击事件在调整大小时被触发

[英]jQuery UI: Click event is being triggered on resize

我正在使用可调整大小的jQuery Ui。 但是调整大小事件会触发元素本身的click事件和其父元素的click事件。 我尝试使用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();
    },

})

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

也许这将为您工作:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM