javascript - 父元素onclick中的子元素onclick
问题描述
我在“div标签”中有一个“支票簿”,“div标签”已经注册了一个onclick事件,当我点击复选框时,它会调用“div标签”的事件,如何捕获事件“支票簿”,我为支票簿尝试了“z-index”,但没有奏效
解决方案
试试这个将解决我添加的问题if (e.target !== this)
。
$('.comment_item').on('click', function(e) {
if (e.target !== this)
return;
alert( 'comment_item' );
});
$('.check-item').on('click', function(e) {
if (e.target !== this)
return;
alert( 'check-item' );
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="comment_item">
<input type="checkbox" class="check-item">
</div>
推荐阅读
- docker - 如何在两个服务之间共享 docker 卷,其中一个是事实来源?
- python - 并行化pytorch中的嵌套for循环
- python - python:pyti平均真实范围函数输入的列表结构
- django - django rest框架知道视图是类还是函数
- php - 如何使用 Laravel 在数据库中搜索未知的属性名称
- dataweave - 无法在 dataweave 中转换 json 数组
- asp.net-core - .net 核心 BlockingCollection 的多个动态消费者
- java - 这个模拟代码不编译的原因是什么?
- asp.net - VB.net aspX 图像调整大小和创建文件权限被拒绝
- javascript - javascript 是否具有与 php 魔术类 __call 等效的功能