我有2个p
<p id="type2" class='hidden' style="position:fixed;width:300px;height:400px;text-align:center;left:200px;top:100px;background-color:white";>
</p>
js动态往id = type2的p里添加一个p
type2的p有一个鼠标事件
$('#type2').mouseout(function(){
$("#type2" ).addClass('hidden');
$("#type2").html("");
});
但是我鼠标移到动态添加的的p时没有离开id=type2的p时触发了这个鼠标移除事件,怎么不触发?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
改mouseout 为 mouseleave 试试 看看这里
事件冒泡引起的 需要加上阻止冒泡的方法
e.stopPropagation() || e.cancelBubble
https://www.oschina.net/code/...
能把你的问题在讲清楚一点嘛~ 什么叫做:触发了这个鼠标移除事件,怎么不触发?
可以使用mouseenter mouseleave事件,这样就不会多次触发了。。。
@caryhgq 的答案是正确的。
我这边再补充一种方法,可以给#type2 内的p添加 pointer-events: none 属性;