jQuery:如何删除醉意的工具提示?

我使用.placeTaken类将divy工具提示添加到div。 然后用户可以拖动框,所以我删除了类并将其添加到新的div中。 当发生这种情况时,我向该div添加了一个新的醉意工具提示,并且工作正常,但我想删除旧的。

他们说如果您希望通过将title属性设置为空字符串来删除工具提示,请改为设置original-title属性。 我试过$("#"+dropFromId).attr("original-title", ""); 但工具提示仍在那里。 我甚至无法通过设置另一个原始标题来更改工具提示标题。

我究竟做错了什么?

编辑:我想我没有给你们足够的信息。 我使用ajax来获取从数据库中获取的位置。 PHP返回一个关联数组(客户),然后我在我的JavaScript中使用,其中发生的地方与名称匹配。 删除时所采取的位置会发生变化,因此我再次执行ajax函数以使用所有拍摄的位置更新数组。 首先,我将醉意的工具提示添加到所有拍摄的地方,如此

 $("#map div.placeTaken").tipsy({gravity: 'w', html: true, fade: true, title: function(){ // id could for example be map74, substring to 74 var id = $(this).attr("id").substring(3,6); return '
'+customers[id]+'

'; } });

所以标题等于数组中匹配的位置。 我希望我能够解释这个问题。 当盒子放在一个新的地方时,就会发生这种情况

 $("#map div span").bind( "dragstop", function(event, ui) { // some code here to change the .placeTaken class // update database with the new place $.ajax({ type: "POST", url: "map.php", data: "dropFromId="+ dropFromId.substring(3,6) +"& dropToId="+ dropToId.substring(3,6), success: function(){ // ajax function to update the js array with new places customerTooltip(); } }); // on this place, add tooltip $("#"+dropToId).tipsy({gravity: 'w', html: true, fade: true, title: // funktion för att avgöra vilken title som ska användas function(){ var id = dropToId.substring(3,6); return '
'+customers[id]+'

'; } }); } });

这一切都很好,所以我认为我只需将DropFromId标题更改为“”,以便我删除它。

使用$(".tipsy").remove(); 似乎可以解决这个问题,因为当显示工具提示时,带有提示类的div会附加到doc的主体上。

请确保你不要在其他地方使用一个小tipsy课程(即调用你的工具提示,比如toolTip

删除醉酒的最简单方法;

 $('.tipsy:last').remove(); 

如果你不想再显示.tipsy('disable') ,只需在元素上使用.tipsy('disable')

如果你正在使用trigger: manual而你想要隐藏它,你可以删除身体上的.tipsy div。

还有disable enabletoggleEnabled

 $("#"+dropFromId)[0].setAttribute('original-title', '') 
 $("#tipsyfiedElement").unbind('mouseenter mouseleave'); // Or whatever event trigger the tiptool 

我最近有这个问题,这是我如何解决它:

使用此选项将original-title属性设置为“stop”:

 $('.myElement').attr('original-title','stop'); 

然后,在jquery.tipsy.js中 ,将代码更改为以下内容:

 ... } else if (typeof opts.title == 'function') { title = opts.title.call(this); } if (title != 'stop') { //line 32 ... ... } //line 62 ... 

在我的发布(0.1.7)中,添加的代码从第32行开始,在第62行结束括号.Thisy应该看到你的title属性等于’stop’并且不会尝试打开工具提示。

此外,这会向控制台吐出一些错误。 它没有任何区别,但是如果你想摆脱它,在第73行添加它(在添加以前的代码之后)

 try { tip.remove(); } catch(err){} 

POW

使用:.unbind(’mouseenter mouseleave’); 删除一个醉意的方法。

由于触摸/点击事件的复杂性,特别是在iPad上,谷歌搜索了一个在移动设备上禁用Tipsy的情况之后我看到了这个问题。

我决定实现的解决方案是在jquery.tipsy.js文件的顶部添加一个小测试。

要在触摸(移动)设备上禁用Tipsy:var deviceAgent = navigator.userAgent.toLowerCase();

 var isTouchDevice = Modernizr.touch || (deviceAgent.match(/(iphone|ipod|ipad)/) || deviceAgent.match(/(android)/) || deviceAgent.match(/(iemobile)/) || deviceAgent.match(/iphone/i) || deviceAgent.match(/ipad/i) || deviceAgent.match(/ipod/i) || deviceAgent.match(/blackberry/i) || deviceAgent.match(/bada/i)); function Tipsy(element, options) { this.$element = $(element); this.options = options; this.enabled = !isTouchDevice; this.fixTitle(); }; 

请参阅:检测用户代理是否支持触摸的最佳方法

使用方式更简单:

 $('body').find('.tipsy').each(function(){ $(this).remove(); });