jQuery UI工具提示:单击工具提示本身即可关闭
jQuery UI Tooltip: Close on click on tooltip itself
我有一个带有jQuery UI工具提示的页面,该工具提示最初是打开的,并且它在mouseout
事件上的关闭被禁用。
现在,我希望工具提示在用户单击它本身之后关闭,而不是在显示工具提示的元素上(就像这里的许多其他答案一样)。
作为可能的解决方案之一,我想我可以向工具提示的div添加一个click
处理程序,然后从那里关闭它。但是,我找不到一种标准的方法来使用tooltip小部件API获取工具提示的div,或者以其他方式附加处理程序。
我采用上述方法是否正确?或者如何以不同的方式实现我所追求的?
JSFiddle说明我目前拥有的内容。
我找到了一个相对简单的解决方案,通过在工具提示的open
事件中附加click
处理程序并关闭那里的工具提示,无需破解Tooltip API:
$('.first')
.tooltip({
content: 'Click to close',
position: { my: 'left center', at: 'right center' },
items: '*'
open: function (event, ui) {
var $element = $(event.target);
ui.tooltip.click(function () {
$element.tooltip('close');
});
},
})
.tooltip('open')
.on('mouseout focusout', function(event) {
event.stopImmediatePropagation();
});
JSFiddle
试试这个:
$(document).ready(function(){
$('.first')
.tooltip({ content: 'Click to close', position: { my: 'left center', at: 'right center' }, items: '*' })
.tooltip('open')
.on('mouseout focusout', function(event) {
event.stopImmediatePropagation();
})
// when the tooltip opens (you could also use 'tooltipcreate'), grab some properties and bind a 'click' event handler
.on('tooltipopen', function(e) {
var self = this, // this refers to the element that the tooltip is attached to
$tooltip = $('#' + this.getAttribute('aria-describedby')); // we can get a reference to the tooltip via the `aria-describedby` attribute
// bind a click handler to close the tooltip
$tooltip.on('click', function() {
$(self).tooltip('close');
});
});
});
- 更新的JSFiddle
- jQuery UI工具提示API
试试这个:
$(document).ready(function(){
$('.first').on('mouseout focusout', function(event) {
event.stopImmediatePropagation()
})
.tooltip({ content: 'Click to close', position: { my: 'left center', at: 'right center' }, items: '*' }).tooltip('open');
$( "body" ).delegate( ".ui-tooltip", "click", function() {
$('.first').tooltip('close');
});
});
请参阅此处的小提琴
根据Alexes回答,如果你只想在点击"X"时关闭:
$(".t1").tooltip({
content: "<div><div class='tit'>Some super titlet</div> <div class='x'>x</div><div class='con'>Some content super super long</div></h1>",
disabled: true,
width:550,
tooltipClass: "myClass",
open: function (event, ui) {
var $element = $(event.target);
ui.tooltip.each(function () {
$("div.x",this).click(function () {
$element.tooltip('close');
});
});
},
}).on('mouseout focusout', function(event) {
event.stopImmediatePropagation();
});
$(".tooltip").click(function() {
$(this)
.tooltip("open")
});
请在此处查看:http://jsfiddle.net/analienx/h639vzaw/73/
相关文章:
- 语义UI中格式化的工具提示
- jQuery UI工具提示:单击工具提示本身即可关闭
- jQuery UI 工具提示位置的奇怪行为
- d3.js svg元素上的角度UI工具提示
- jquery UI工具提示的自定义背景图像
- 剑道ui工具提示在网格中的定位问题
- jQuery UI 工具提示在源 DOM 元素移动时卡住打开
- $(..).工具提示不起作用,因为 jQuery 1.9.2 由于旧的 jQuery UI 1.8.16 库而不起作用?
- 使剑道 UI 下拉列表将“选择控件”的“标题”属性显示为剑道工具提示
- IE8,jQuery UI 工具提示在 Internet Explorer 8 中立即关闭
- “初始化前无法在工具提示上调用方法”错误,当我添加 jquery-ui 库时
- 无法将表单输入字段上的 JQuery UI 工具提示限制为仅在单击/焦点事件上显示
- UI 引导程序 - 如何防止在下拉列表打开时打开工具提示
- 更新 jQuery UI 工具提示上的数字
- 如何使用 i18next 本地化属性(对于 jQuery UI 工具提示,在我的情况下使用标题)
- 在我的自定义指令中动态添加 bootstrap.ui 工具提示
- 在 jquery UI 工具提示中显示加载效果
- 如何为新加载的元素提供JQuery UI工具提示
- JQuery UI工具提示:每个工具提示有不同的图像
- jQuery工具提示UI -触发工具提示后x秒