[英]jQuery : Kill Mouseenter/mouseleave function on mouseleave
我在mouseenter / mouseleave函數方面遇到一些問題。
請看一下我的代碼;
$(".elms").live(
{
mouseenter: function (e)
{
$("a").click(function()
{
alert('test');
});
},
mouseleave: function (e)
{
//do something else
}
});
html:
<div class='elms'>test [ function says `test` ]</div>
<div class='elms'>test [ function says `test` and `test` ]</div>
<div class='elms'>test [ function says `test` and `test` and `test` ]</div>
<div class='elms'>test [ function says `test` and `test` and `test `test` and `test` ]</div>
這甚至會重復90個元素,我想在休假時終止功能並制作一個新元素。 像這樣的東西:
var killIt = $(".elms").live(
{
mouseenter: function (e)
{
$("a").click(function()
{
alert('test');
});
},
mouseleave: function (e)
{
killIt.die();
}
});
有任何想法嗎?
[小提琴: http : //jsfiddle.net/29f3P/ ]
如果您每次必須銷毀監聽器,請嘗試jQuery.one(),它將在首次調用后自動銷毀監聽器。
如果監聽器不一定必須運行一次,請嘗試使用jQuery.off()取消綁定監聽器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.