【问题标题】:Open Jquery-ui Tooltip only on click仅在单击时打开 Jquery-ui Tooltip
【发布时间】:2015-02-27 14:14:41
【问题描述】:

我有这个代码

function DrawTipsProgress(postid, ajaxurl) {

    var data = {
        action: 'ajax_action',
        post_id: postid
    }

    jQuery('#dashicon-' + postid).on("click", function () {

        jQuery.post(ajaxurl, data, function(response) {

            jQuery('#dashicon-' + postid).tooltip({

                position: { my: 'center bottom' , at: 'center top-10' },
                tooltipClass: "myclass",
                content: response

            });

            jQuery('#dashicon-' + postid).tooltip('open');

        });

    });

}

第一次点击时,它按方面工作。 如果稍后我尝试再次悬停按钮而不单击它,则再次弹出工具提示,单击只是执行 ajax 调用,但不会打开工具提示。

【问题讨论】:

    标签: javascript jquery ajax jquery-ui jquery-ui-tooltip


    【解决方案1】:

    工具提示在悬停时触发。在您的代码中,在“点击”事件发生之前它不会被绑定到元素,所以它并不是真正的点击导致它显示......它是点击之后的悬停。我相信您需要做的是使用enabledisable。这是一个示例小提琴。 http://jsfiddle.net/ecropolis/bh4ctmuj/

    <a href="#" title="Anchor description">Anchor text</a>
    
    $('a').tooltip({
        position: { my: 'center bottom' , at: 'center top-10' },
        tooltipClass: "myclass",
        disabled: true,
        close: function( event, ui ) { 
            $(this).tooltip('disable'); 
            /* instead of $(this) you could also use $(event.target) */
        }
    });
    
    $('a').on('click', function () {
         $(this).tooltip('enable').tooltip('open');
    });
    

    【讨论】:

    • 这是一个接受的答案应该是什么样子,带有解释和工作示例。谢谢。
    • 添加ajax,使其完整
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多