试一试
mouseenter
和
mouseleave
事件:
$('a.ftelement').mouseenter(function(){
$('<a></a>').attr({
"class":"imgfavorito",
"id":"fav"+$J(this).attr("id")
}).html("<img src=\"/im/favorito.gif\"/>")
.appendTo(this);
}).mouseleave(function(){
$(this).find("a.imgfavorito").remove();
});
最好只创建一次链接,然后在其悬停时隐藏/显示链接:
var ftelement = $('a.ftelement').mouseenter(function(){
imgfavorito.show();
}).mouseleave(function(){
imgfavorito.hide();
});
var imgfavorito = $('<a></a>').attr({
"class":"imgfavorito",
"id":"fav"+$J(this).attr("id")
}).html("<img src=\"/im/favorito.gif\"/>")
.appendTo(ftelement);