簡體   English   中英

Jquery懸停在.on()

[英]Jquery hover with .on()

我試圖使用.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

原來非.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(){});

要么

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

有一個答案:

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

這很有效,出於某種原因,我在1.9.1命名文件中有JQ 1.4導致問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM