Jquery在使用Firefox浏览时不起作用



你好,我正在使用这个代码:

$("#cart").click(function () {
    if ($(event.target).closest('.content').length > 0) return false;
    $('#cart').load('index.php?route=module/cart #cart > *');
    var e = window.event || e;
    $("#cart").toggleClass("active");
    e.stopPropagation();
    $(document).click(function (e) {
        $("#cart").removeClass("active");
        $('#cart').live('mouseleave', function () {
            // Code Here
        });
    });
});

它在Chrome中运行良好,但是在Firefox中测试时它不起作用。不起作用的行是:

if ($(event.target).closest('.content').length>0) return false; 

为什么这在 Chrome 中有效,但在 火狐 中不起作用?

您没有传递事件参数

像这样尝试

$("#cart").click(function(event) {
  // now put your code here
}

您忘了添加event作为听众的参数。

$("#cart").click(function (event) {
    if ($(event.target).closest('.content').length > 0) return false;
    $('#cart').load('index.php?route=module/cart #cart > *');
    var e = window.event || e;
    $("#cart").toggleClass("active");
    e.stopPropagation();
    $(document).click(function (e) {
        $("#cart").removeClass("active");
        $('#cart').live('mouseleave', function () {
            // Code Here
        });
    });
});

最新更新