代码只执行一次,但应该继续执行

Code only executes once but should continue

本文关键字:执行 继续 一次 代码      更新时间:2023-09-26

下面的代码应该会阻止弹出窗口关闭,如果你将鼠标悬停在它或按钮上,但是,它只在重新加载时工作一次,然后停止工作。

$('.popover3-test').popover({
    placement:'bottom',
    template: $('.popover2'),
    trigger: 'manual',
    }).mouseenter(function(e) {
    $(this).popover('show');
    var t = null;
    $(".popover2, .popover3-test")
        .mouseleave(function() {
            t = setTimeout(function() {
                $('.popover2').hide();
            }, 1000); // Or however many milliseconds
        })
        .mouseenter(function() {
            if(t !== null)
                clearTimeout(t);
         });
    });

演示:http://jsfiddle.net/MnpWV/1/

试试这个:

$(".popover2, .popover3-test")
        .mouseleave(function() {
           $('.popover2').delay(1000).fadeOut('1000');
        }
});

http://jsfiddle.net/MnpWV/8/

更新:

$(".popover2").hover(function(e) {
    $(this).show()
}, function() {
    $('this').delay(1000).fadeOut('1000');
})

http://jsfiddle.net/MnpWV/16/

删除触发mouseleave事件的.popover3-test