javascript - 单击特定项目时执行js函数
问题描述
请告诉我go2
当我单击按钮而不执行该功能时如何执行该go
功能
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>
解决方案
你需要使用 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>
推荐阅读
- javascript - JavaScript 秒表 - 无法显示前导数字
- java - 在 Java 10 中运行 JavaFX 8 应用程序,以更大的窗口和不同样式的内容呈现
- python - 比较两个字典列表和输出差异
- python - 为什么即使我有适当的异常处理,我的 python 代码也会终止?
- php - 添加到 Woocommerce 的自定义元数据未显示在订单项元中
- sql-server - 通过进一步分组进行分组
- c - 使用 snprintf 在 c 中连接给出分段错误
- asp.net-core - 从 Visual Studio 和 .NET Core 服务更新发布,最好的解决方法是什么?
- cron - 删除由 cronjob 创建的所有 k8s pod
- python - keras,模型(数据)是什么意思