gpt4 book ai didi

jquery - 带有 SVG onclick 问题的 HTML

转载 作者:行者123 更新时间:2023-11-28 14:35:20 24 4
gpt4 key购买 nike

我有一个带有包含我的 svg 的子对象标签的父 div。

我正在 try catch 对我的图片的点击,但它不起作用。

在示例代码片段中,仅当单击位于显示的 svg 之外时才会显示警报。

HTML:

<div class="calendarWidget" onclick="alert('test');">
<span>
<object onclick="alert('test1');" data="https://www.multiservicetolls.com/wp-content/uploads/revslider/assets/svg/busy-icons-svg/folder-private.svg" type="image/svg+xml"></object>
</span>
</div>

CSS:

.calendarWidget {
position: fixed;
max-width: 200px;
width: 200px;
right: 20px;
bottom: 20px;
background-color:green;
z-index: 1;
}

JSFiddle

由于我的要求,我无法在svg中编写脚本代码。

最佳答案

可能最简单的方法是将处理程序保留在 div 上,并使用 css pointer-events: none; 将浏览器设置为忽略 svg 上的鼠标事件。运行下面的代码片段以查看它是否有效(为了演示,我将 svg 移到了左上角)。

.calendarWidget {
position: fixed;
max-width: 200px;
width: 200px;
left: 20px;
top: 20px;
background-color:green;
z-index: 1;
}
.ignoreMouse{
pointer-events: none;
}
<div class="calendarWidget" onclick="alert('test');">
<span>
<object class="ignoreMouse" data="https://www.multiservicetolls.com/wp-content/uploads/revslider/assets/svg/busy-icons-svg/folder-private.svg" type="image/svg+xml"></object>
</span>
</div>

关于jquery - 带有 SVG onclick 问题的 HTML <div>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53596986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com