javascript - HTML:如何使点击监听器忽略放置在图标上的不可见按钮
问题描述
我正在尝试制作一个模式窗口,该窗口通过单击下面代码中的问号图标触发。
<label class="control-label col-md-4 col-lg-3" for="offer_offer" id=Angebotlbl>
<div class="inline-help form-label" ><i class="fa fa-question-circle-o" id="AngebotHilfe"></i>
<button id="hilfeBtn" data-modal-target="#modal"></button>
</div>Angebot</label>
我真的不知道 HTML 或 .css。在尝试并未能使该图标可点击后,我考虑创建一个透明/不可见的按钮并将其放在该图标的正上方。.css 看起来像这样:
#hilfeBtn {
background-color:Transparent;
-webkit-border-radius: 60;
-moz-border-radius: 60;
border-radius: 60px;
font-family: Arial;
color: #ffffff;
font-size: 20px;
padding: 12px 12px 12px 12px;
border: solid #1f628d 0px;
text-decoration: none;
position:absolute;
top: 22%;
left: 5%;
}
##hilfeBtn:hover {
background: #3cb0fd;
background-image: -webkit-linear-gradient(top, #3cb0fd, #3498db);
background-image: -moz-linear-gradient(top, #3cb0fd, #3498db);
background-image: -ms-linear-gradient(top, #3cb0fd, #3498db);
background-image: -o-linear-gradient(top, #3cb0fd, #3498db);
background-image: linear-gradient(to bottom, #3cb0fd, #3498db);
text-decoration: none;
}
但可能我的计划很愚蠢。因为现在我不能真正添加一个事件监听器到上面的图标“Angebothilfe”没有事件监听器忽略它上面的不可见按钮。我的事件监听器看起来像这样:
formElements[i].addEventListener("click", function(event) {
focusFunction(event);
});
function focusFunction(event) {
console.log("clickedOn," +event.target.id+","+ Date.now())
还有另一种方法吗?
解决方案
尝试这个:
<div class="inline-help form-label" onclick="myFunction()" >
<i class="fa fa-question-circle-o" id="AngebotHilfe"></i>
</div>
“myFunction()”会做任何你想做的事。
推荐阅读
- python - 子命令问题:ctx.invoked_subcommands 始终为 None
- python - 遍历列表直到满足 2 个条件
- c# - 为什么我在 UWP 中收到此错误“...无法解析程序集:System.Runtime”?
- python - 使用 pandas 和 fuzzwuzzy 匹配相似的列元素
- c# - 序列化异常返回一个非常大的 JSON
- python - 如何在 html div 中显示 Python print()
- mysql - SQL将值与特定年份的平均值进行比较
- python - 在 Kivy 中使用按钮释放清除 inputText
- amp-html - URL 中带有斜杠的 AMP 分析源
- java - 如何在 zip 中写入字节数组,然后从那里读取