javascript 仅在单击时打开 Jquery-ui 工具提示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28767137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open Jquery-ui Tooltip only on click
提问by Dudo1985
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 调用,但不会打开工具提示。
回答by Ecropolis
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. I believe what you need to do is use enableand disable. Here is an example fiddle. http://jsfiddle.net/ecropolis/bh4ctmuj/
工具提示在悬停时触发。在您的代码中,在“click”事件发生之前,它不会绑定到元素,所以它并不是真正的点击导致它显示......它是点击后的悬停。我相信您需要做的是使用enable和disable。这是一个示例小提琴。 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');
});