【发布时间】:2017-05-03 20:27:42
【问题描述】:
我有一个按钮,里面有一个跨度。我在按钮上有一个点击事件,在跨度上也有一个点击事件,但在 IE11 中,跨度点击事件没有触发(在 Chrome/Firefox 中有效)。在不从按钮更改为 div 的情况下,是否有任何解决方法?
我知道将我的按钮更改为 div 会起作用(正如其他问题中所回答的那样),我想避免这样做。
https://jsfiddle.net/asjo8ox0/2/
$(document)
.on("click", ".parent", function() {
alert("parent");
})
.on("click", ".child", function(e) {
alert("child");
e.stopPropagation();
})
.parent {
width: 200px;
height: 200px;
background-color: cornflowerblue;
}
.child {
width: 100px;
height: 100px;
background-color: white;
display: none;
}
.parent:hover .child {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="parent">
<span class="child"></span>
</button>
【问题讨论】:
-
您正在尝试的 IE 版本?
-
@NagaSaiA 我正在 IE11 中对此进行测试,将其添加到我的问题中
-
e 在您的点击事件中不存在... on("click", ".child", function(e) { alert("child"); e.stopPropagation(); } )
-
@serverSentinel 是的,刚刚解决了这个问题,谢谢,但这不是问题
-
将您的按钮标签更改为 div。 IE 不支持它。
标签: javascript jquery html css