jQuery:使用on函数加载插件

jQuery : load a plugin using on function

本文关键字:加载 插件 函数 on 使用 jQuery      更新时间:2023-11-24

我使用的是jQuery和Tooltipster(在悬停用户名时显示工具提示),它们运行得很好,只有一种情况:当我第一次悬停用户名时,它不会显示。

<div class="user">Firstname Lastname</div>

这是我的jQuery代码:

$(document).ready(function() {
  $(document).on('mouseover', '.user', function() {
    // Tooltip for EC user
    $('.evac_user').tooltipster({
        animation : 'fade',
        delay : 0,
        content : 'Loading...',
        functionBefore : function(origin, continueTooltip) {
            continueTooltip();
            // next, we want to check if our data has already been cached
            if (origin.data('ajax') !== 'cached') {
                $.ajax({
                    type : 'GET',
                    url : "/myfunction",
                    success : function(data) {
                        // update our tooltip content with our returned data and cache it
                        origin.tooltipster('update', data).data('ajax', 'cached');
                    }
                });
            }
        }
    });
  });
});
$('.user').on('mouseover', function(){