检测单击复选框时的工具提示事件

Detecting tooltip event on click of checkbox

本文关键字:工具提示 事件 单击 复选框 检测      更新时间:2023-09-26

我使用qtip2来显示选中复选框时的工具提示。

<input type="checkbox" id="chk1" /> User
$(document).on('click', '#chk1', function(){
    $(this).qtip({
        content: 'This is a test',
        show: 'click',
        hide: 'click'
    });
});

它使用基本的

进行检测
$('#chk1').qtip({
    content: 'This is a test',
    show: 'click',
    hide: 'click'
});

但不是另一个。我如何使它与$(document)参考

一起工作?

这对我很有帮助,不记得我从哪里得到的了:

    // IIFE - Immediately Invoked Function Expression
(function(myfunction) {
    // The global jQuery object is passed as a parameter
    myfunction(window.jQuery, window, document);
}(function($, window, document) {
    // The $ is now locally scoped 
    // Listen for the jQuery ready event on the document
    $(function() {
        // The DOM is ready!
        $(document).on('click', '#chk1', function(){
            $(this).qtip({
                content: 'This is a test',
                show: 'click',
                hide: 'click'
            });
        });
    });
    // The rest of code goes here!
}));

这是元素、jquery等加载过程的不同时刻。我对这个不太感兴趣,但它可能对你有帮助。