鑑於下面顯示的html表和腳本我有一個問題,即鼠標輸入後鼠標離開事件發生,即使我不移動將鼠標移出該行。jquery:mouseleave事件似乎不應該觸發
<script type="text/javascript" language="javascript">
function highlightRows(iMainID)
{
$('tr[mainid=' + iMainID+ ']').each(function() {
if ($(this).attr('old') == undefined) {
$(this).attr('old', $(this).css('backgroundColor'));
}
$(this).animate({ backgroundColor: "#FFFFCC" }, 500);
$(this).mouseout(function() {
if ($(this).attr('old') != undefined) {
$(this).animate({ backgroundColor: $(this).attr('old') }, 500);
}
});
});
}
</script>
<table>
<tr>
<td mainid="1" onmouseover='highlightRows(1)'><div>text</div></td>
<td mainid="1" onmouseover='highlightRows(1)'><div>text</div></td>
<td mainid="2" onmouseover='highlightRows(2)'><div>text</div></td>
</tr>
<table>
你真的不應該在「mouseover」處理程序中設置「mouseout」處理程序。事先分別設置這兩個處理程序,並使用jQuery而不是「onfoo」元素屬性來完成。 – Pointy 2010-03-08 19:01:46
當我有重疊元素時,發生在我身上。計算機在兩個元件之間切換,並且這樣做非常快速地進入和離開。 – 2014-10-26 02:47:47