Javascript Jquery将鼠标悬停在.on()上

Javascript Jquery将鼠标悬停在.on()上,javascript,jquery,css,ajax,Javascript,Jquery,Css,Ajax,我试图使用hover with.on(),但我发现的所有代码和答案都不起作用 我需要使用.on,因为它包含Ajax内容 我试过几次: $(document).on('mouseenter', '[rel=popup]', function() { mouseMove = true; width = 415; $('#tool-tip').show(); var type = $(this).attr('data-type'), id = $(th

我试图使用hover with.on(),但我发现的所有代码和答案都不起作用

我需要使用.on,因为它包含Ajax内容

我试过几次:

$(document).on('mouseenter', '[rel=popup]', function() {
    mouseMove = true;
    width = 415;
    $('#tool-tip').show();

    var type = $(this).attr('data-type'),
        id = $(this).attr('data-skillid');

    console.log("TT-open");
    ttAjax(type, id);
}).on('mouseleave', '[rel=popup]', function() {
    mouseMove = false;
    console.log("TT-close");
    $('#tool-tip').hide();
    $('#tt-cont').html("");
    $('#tt-ajax').show();
});

$('[rel=popup]').on('hover',function(e) { 
    if(e.type == "mouseenter") {
        mouseMove = true;
        width = 415;
        $('#tool-tip').show();

        var type = $(this).attr('data-type'),
            id = $(this).attr('data-skillid');

        console.log("TT-open");
        ttAjax(type, id);
    }
    else if (e.type == "mouseleave") {
        mouseMove = false;
        console.log("TT-close");
        $('#tool-tip').hide();
        $('#tt-cont').html("");
        $('#tt-ajax').show();
    }
});

$('[rel=popup]').on("hover", function(e) {

    if (e.type === "mouseenter") { console.log("enter"); }
    else if (e.type === "mouseleave") { console.log("leave"); }

});

$(document).on({
    mouseenter: function () {
        console.log("on");
    },
    mouseleave: function () {
        console.log("off");
    }
}, "[rel=popup]"); //pass the element as an argument to .on
原来的非政府组织:

$('[rel=popup]').hover(function(){
    mouseMove = true;
    width = 415;
    $('#tool-tip').show();

    var type = $(this).attr('data-type'),
        id = $(this).attr('data-skillid');

    console.log("TT-open");
    ttAjax(type, id);

},function () {
    mouseMove = false;
    console.log("TT-close");
    $('#tool-tip').hide();
    $('#tt-cont').html("");
    $('#tt-ajax').show();
})

所有.on返回“TypeError:$(…).on不是函数”。我使用的是1.9.1版。

您要查找的事件可能是

$("#id").mouseover(function(){});


答案是:

$(document).on({
    mouseenter: function () {
        console.log("on");
    },
    mouseleave: function () {
        console.log("off");
    }
},"[rel=popup]");

这是有效的,出于某种原因,我在一个1.9.1命名文件中使用了JQ 1.4,这是导致问题的原因。

“hover”不是一个事件。我也使用mouseenter和leave,它们也不起作用。如果您遇到了这个错误,您可能没有真正使用您认为是的jQuery版本,或者有一个
$
冲突。看看这个:它工作得很好。一定要尝试使用
jQuery
而不是
$
。我同意@Pointy,您不能使用1.91。在您的控制台类型中:
$.fn.jquery
,出现了什么?#由jquery管理“mouseenter”和“mouseleave”事件,应该可以正常工作。尽管有上面的评论和否决票,但这不是一个坏建议,因为它可以从jquery 1.0+运行,提问者的问题似乎是他没有使用他认为的版本(或者版本之间存在冲突。)但我真的建议修复版本问题并正确执行。因此,问题在于脚本文件不好-与代码无关。
$(document).on({
    mouseenter: function () {
        console.log("on");
    },
    mouseleave: function () {
        console.log("off");
    }
},"[rel=popup]");