jQuery mouseleave(),mouseout()的使用说明
摘要:当鼠标指针离开元素时,会发生 mouseleave 事件。该事件大多数时候会与 mouseenter 事件一起使用。 HTML: div style='width:300px; height:200px; background:#ccc;'/div Js: $(function(){ $('div').mouseleave(function
当鼠标指针离开元素时,会发生 mouseleave 事件。该事件大多数时候会与 mouseenter 事件一起使用。
HTML:
<div style='width:300px; height:200px; background:#ccc;'></div>
Js:
$(function(){
$('div').mouseleave(function(){
alert('你已经离开我了哦,还想回来吗?');
});
});
HTML:
<div style='width:300px; height:200px; background:#ccc;'></div>
Js:
$(function(){
$('div').mouseleave(function(){
alert('你已经离开我了哦,还想回来吗?');
});
});
运行效果如下:
mouseleave 与 mouseout 的区别:
注释:与 mouseout 事件不同,只有在鼠标指针离开被选元素时,才会触发 mouseleave 事件。如果鼠标指针离开任何子元素,同样会触发 mouseout 事件。
运行以下效果来查看两者直接的区别