简体   繁体   English

如何在Javascript中分隔两个事件

[英]How can I separate two events in Javascript

I Have a <div> Element, which includes a Button. 我有一个<div>元素,其中包含一个Button。 在此输入图像描述

Both have Events. 两者都有活动。 Code for the Button: 按钮代码:

<button Title="Auswahl anzeigen" class="PopUpButton2" onClick="findArticlesFromSearchBoxButton()">OK</button>');  

Code for the Div-Element: Div元素代码:

<div draggable="true" Title="aus aatentechnichen Gr&uuml;nden &#10; k&ouml;nnen beide Suchmethoden &#10; noch nicht miteinander kombiniert werden!" onMouseDown="dragStart(this);" id="divArtikelart">

When I click to the button also the clicks on die div-Elements are executed. 当我点击按钮时,也会执行div div-Elements上的点击。 How can i avoid this? 我怎么能避免这个?

$("button").click(function(event){
    event.stopPropagation();
});

Add stopPropogation at first line in your button click function. 在按钮单击功能的第一行添加stopPropogation。 this should resolve issue 这应该解决问题

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

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