【问题标题】:qtip jquery click not invoking on element inside tooltipqtip jquery单击不调用工具提示内的元素
【发布时间】:2014-08-26 17:54:16
【问题描述】:

我正在使用 jquery qtip (http://qtip2.com/)

它工作得很好,我里面有一些带有类的 div

我正在尝试在这些 div 上调用点击功能

qtip:

 var tipContent = $('#tip-content').html();
    $('#obsglass').qtip({
        content: {
            text: tipContent
        },
        show: {
            effect: function() {
                $(this).fadeTo(500, 1);
            },
            event:'click'
        },
        hide: {
            effect: function() {
                $(this).slideUp();
            },
            event:'click unfocus'

        },
        //show: 'click',
        //hide: 'click unfocus',
        style: {
            classes: 'qtip-bootstrap qtip-shadow',

        },

        position: {
            my: 'center left',  // Position my top left...
            at: 'center right', // at the bottom right of...
            target: $('#obsglass') // my target
        },


    });

点击功能

 $(".obsglass-thumbnail").click(function () {

... 点击工具提示中的div时不进入该功能

【问题讨论】:

    标签: jquery qtip qtip2


    【解决方案1】:

    您的元素似乎已被插件动态添加到 DOM,请尝试在此处使用 event delegation

    $(document.body).on('click','.obsglass-thumbnail',function() {
        // Your code here
    })
    

    【讨论】:

      【解决方案2】:

      而不是,

       $(".obsglass-thumbnail").click(function () {})
      

      使用委托:

       $(document).delegate(".obsglass-thumbnail","click",function () {})
      

      因为,如果在加载 Click 事件后添加了 HTML 元素,则您的事件对这些元素没有用处。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多