我有这个代码
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 调用但不会打开工具提示。
最佳答案
悬停时触发工具提示。在您的代码中,在“点击”事件发生之前,它不会绑定(bind)到元素,因此导致它显示的并不是真正的点击……它是点击后的悬停。我相信你需要做的是使用 enable和 disable .这是一个示例 fiddle 。 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');
});
关于javascript - 仅在单击时打开 Jquery-ui 工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28767137/