$(".hover").hover(function(){ $(this).css("background","#008000"); },function(){ $(this).css("background","#fff"); }); $(".bind").click(function(){ alert("bind"); $('.hover').bind("hover"); }); $(".unbind").click(function(){ console.log("unbind succ==="); $('.hover').unbind('mouseenter').unbind('mouseleave'); });重新绑定,并没有成功,也就是 $('.hover').bind("hover");这个话没有执行。那有什么方法重新绑定hover事件吗?
1 回答
HUX布斯
TA贡献1876条经验 获得超6个赞
事件绑定起码得有俩参数,分别是事件名和处理function。建议再去看看教程或者文档;
这个API有点老了(没记错的话jQ3已经彻底甩掉
.bind()
了,.toggle()
在1.9就已经淘汰了),建议用新版API,.on()
、.off()
等;修改(不知道绑的hover是干嘛用的,权且移花接木):
function mEnter () { $(this).css("background","#008000"); }function mLeave () { $(this).css("background","#fff"); } $(".bind").click(function(){ console.log('bind!'); $('.hover') .on('mouseenter', mEnter) .on('mouseleave', mLeave); }); $(".unbind").click(function(){ console.log('unbind!'); $('.hover') .off('mouseenter', mEnter) .off('mouseleave', mLeave); });
添加回答
举报
0/150
提交
取消