我有這個完整的演示代碼。我想當鼠標懸停在綠色div上時顯示藍色div,並在鼠標移出綠色div時隱藏藍色div。問題是,當我將鼠標懸停在綠色並向上移動時,鼠標實際上不在綠色區域,但藍色不會消失。如何解決這個問題?Mouseout在父級>子級上不起作用
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.js"></script>
<script>
$(document).ready(function(){
$(document).on({
mouseover: function(e){
$(".inner").show();
$(".message").text("OVER");
},
mouseleave: function(e){
$(".inner").hide();
$(".message").text("OUT");
}
}, ".outer");
});
</script>
<style>
.outer {
padding: 20px;
background: green;
margin: 50px 0 0 0;
}
.inner {
display: none;
background: blue;
height: 30px;
width: 300px;
position: absolute;
left: 8;
top: 25;
}
</style>
</head>
<body>
<div class="outer">
OUTER
<div class="inner">INNER</div>
</div>
<div class="message"></div>
</body>
</html>
您的代碼有一個小問題。當我將鼠標從底部移到頂部時,藍色出現然後消失。想象一下,藍色是一個工具提示,藍色不應該消失,然後鼠標仍然是綠色的。 – Emerald214