javascript - CSS在圆圈外点击会导致事件
问题描述
我有一个用border-radius
. 如果我单击截止区域,事件仍然会触发。我如何在本地防止这种情况?或者是在 JS 中检查它的唯一解决方案?
解决方案
我试图重新创建您的案例,并且效果很好。使用div
+border-radius
方法和svg
document.getElementById("circle1").onclick = function() {
alert("svg clicked")
}
document.getElementById("circle2").onclick = function() {
alert("div clicked")
}
.circle {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: tomato;
}
<svg height="100" width="100">
<circle cx="50" cy="50" r="50" fill="red" id="circle1"/>
</svg>
<div class="circle" id="circle2"></div>
推荐阅读
- c++ - 反转数组但只有一个元素返回
- php - MySQL事务如何工作以及何时回滚?
- python - 日期作为图表的水平轴:如何格式化标签并设置范围?
- tomcat - OS X 上的 Tomcat 9.0.16:Safari 无法通过 HTTP/2 加载 gzip 压缩的内容
- javascript - 在循环内定义变量
- ruby-on-rails - 仅在 rake 任务完成后运行邮件程序
- php - 将带有 URL 的域重定向到带有 URL 的子域
- c# - C# - FluentNHibernate 映射,如何使用生成器映射表中的非键列
- facebook - 已发布的 Facebook 应用程序未显示
- node.js - 如何为电子版本 4.0.x 安装 gRPC