我想在按鈕mouseout
中使用setTimeout
並參考setTimeout
中的$(this)
(按鈕)。我使用that = $(this)
,然後用在setTimeout
that
但很喜歡它預期不起作用。
如果你將鼠標懸停在每一個環節慢慢它的工作原理(1,2,3)。但是如果你以100ms的速度快速完成,我會獲得所有3s(3,3,3)。
我的猜測是關閉不工作和that
VAR被覆蓋,但我就是想不通爲什麼。
你能解釋發生了什麼?
$("nav a")
.mouseenter(function() {
//
})
.mouseout(function(event) {
\t that = $(this);
\t setTimeout(function(){
\t \t console.log(that.data('uid'));
}, 100);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav>
<ul>
<li><a href="" data-uid="1">One</a></li>
<li><a href="" data-uid="2">Two</a></li>
<li><a href="" data-uid="3">Three</a></li>
</ul>
</nav>
'VAR是= ...'; –