简体   繁体   English

单击表单下方元素的鼠标单击触发事件

[英]Mouse Click Triggering Event of Element below Form being clicked

I have a submit button (form) hovering over an image thumbnail which allows the user to delete the image as seen below 我有一个“提交”按钮(窗体),悬停在图像缩略图上方,允许用户删除图像,如下所示

问题的例子

The thumbnail (img element) also has an onclick event which triggers a popup displaying the image in full size. 缩略图(img元素)还具有onclick事件,该事件触发一个弹出窗口,以全尺寸显示图像。 Unfortunately, when I click the 'x' button (submit the form), the onclick event for the thumbnail image below also gets triggered so that the user is shown a popup before the page is redirected. 不幸的是,当我单击“ x”按钮(提交表单)时,下面的缩略图的onclick事件也会被触发,以便在重定向页面之前向用户显示一个弹出窗口。 How can I prevent this? 我该如何预防?

Additional Info 附加信息

The css for the button is as so: 按钮的css如下:

.delete_image_button
{
    position:               absolute;
    top:                    0px;
    right:                  0px;
    z-index:                1;
}

您可以使用jQuery 停止传播功能,它可以防止事件冒泡

You can use stopPropagation method for prevent the event from propagating to parent node. 您可以使用stopPropagation方法来防止事件传播到父节点。

$(element).click(function(event){
     event.stopPropagation();
});

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

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