简体   繁体   English

仅在单击时打开Jquery-ui工具提示

[英]Open Jquery-ui Tooltip only on click

I've this code 我有这个代码

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');

        });

    });

}

On first click, it work as aspected. 在第一次单击时,它按预期工作。 If later I try to hover again the button without click it the tooltip popup again, and the click just do the ajax call but doesn't open the tooltip. 如果稍后我尝试再次悬停按钮而不再单击工具提示弹出窗口,并且单击只是执行ajax调用但不打开工具提示。

The tooltip is triggered on hover. 悬停时会触发工具提示。 In your code, it is not being bound to the element until the 'click' event occurs, so it's not really the click causing it to display... it's the hover following the click. 在你的代码中,它不会被绑定到元素,直到'click'事件发生,所以它不是真正的点击导致它显示...它是点击后的悬停。 I believe what you need to do is use enable and disable . 我相信你需要做的是使用启用禁用 Here is an example fiddle. 这是一个小例子。 http://jsfiddle.net/ecropolis/bh4ctmuj/ 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');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM