[英]Execute js function when a specific item is clicked
Please tell me how I can execute the go2
function when I click on the button without executing the go
function请告诉我如何在不执行
go
函数的情况下单击按钮时执行go2
函数
function go($i) { alert($i); } function go2($i) { alert($i); }
div { width: 200px; height: 200px; background: #eaeaea; }
<div onclick="go('159');"> <button onclick="go2('160');">Go 2</button> </div>
you need to use event.stopPropagation()你需要使用 event.stopPropagation()
function go($i) { alert($i); } function go2($i) { event.stopPropagation(); alert($i); }
div { width: 200px; height: 200px; background: #eaeaea; }
<div onclick="go('159');"> <button onclick="go2('160');">Go 2</button> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.