2013-02-12 55 views

回答

8

在1.9.1你应该使用mouseover

$(document).on("mouseover", "#cart-left", function(){ 
    $("#cart").addClass('active'); 
}); 
5

hover速记

状态在jQuery 1.8的hover速记已经弃用。见jQuery on() documentation

弃用的jQuery 1.8:名称用作字符串 “的mouseenter鼠标离开”

在jQuery 1.9的速记 “盘旋”,该hover速记是不受支持 。见jQuery 1.9 Upgrade Guide

替代

在你的情况,这意味着你应该使用mouseenter事件。例如:

$(document).on("mouseenter", "#cart-left", function(){ 
    $("#cart").addClass('active'); 
}); 

jsFiddle demo

制作的on()

另外值得一提的是,除非选择传递给on()是指被添加到DOM动态元素更好的使用(即在页面加载后),则不需要委托人处理程序到document。相反,在这种情况下,你或许可以绑定处理函数直接的元素,像这样:

$("#cart-left").on("mouseenter", function(){ 
    $("#cart").addClass('active'); 
}); 
相关问题