2010-08-10 48 views
13

我用.placeTaken類爲div添加醉意的工具提示。用戶然後可以拖動框,所以我刪除類並將其添加到一個新的div。發生這種情況時,我爲該div添加了一個新的提示性工具提示,並且工作正常,但我想刪除舊的提示。jQuery:如何刪除醉tool tool的工具提示?

他們說,如果您希望通過將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 '<div>'+customers[id]+'</div><br />'; 
    } 
}); 

所以標題等於什麼數組中的位置相匹配。我希望我解釋得這麼好。當框在一個新的地方下降了,這是什麼情況

$("#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 '<div>'+customers[id]+'</div><br />'; 
      } 
     }); 
    } 
}); 

這一切工作正常,所以我想我會簡單地改變dropFromId標題爲「」的下降,讓我將其刪除。

+0

你能提供一些示例代碼,顯示問題? – 2010-08-10 13:27:22

+0

你應該發佈你的html,因爲tooltip來自'title'屬性,除非你使用了一些自定義屬性。 – Sarfraz 2010-08-10 13:29:45

+0

好的,我發佈了一些代碼。 – Charles 2010-08-10 14:02:20

回答

2
$("#"+dropFromId)[0].setAttribute('original-title', '') 
+0

這是正確的,並且是由醉意作者建議的方法:http://onehackoranother.com/projects/jquery/tipsy/#options – Sam 2011-12-29 05:07:38

1
$("#tipsyfiedElement").unbind('mouseenter mouseleave'); // Or whatever event trigger the tiptool 
26

使用$(".tipsy").remove();似乎這樣的伎倆,因爲有tipsy類股利顯示工具提示時,附加到文檔的主體。

只要確保你不使用tipsy類的其他地方(即打電話給你提示的類似toolTip代替)

0

最近我有這個問題,我是這樣解決的:

使用此設置原標題屬性爲 '停止':

$('.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行結束括號。Tipsy應該看到您的title屬性等於「stop」,並且不會嘗試打開工具提示。

此外,這對控制檯吐出一些錯誤。它沒有任何區別,但如果你想擺脫它,

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

POW

11

刪除醉意最簡單的方法(將以前的代碼之後)在73行添加此;

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

非常方便,如果你有一個按鈕分配了醉意,鼠標懸停在按鈕→醉tool tool的提示出現,然後點擊按鈕,醉人被上面的代碼隱藏。謝謝! – 2013-04-09 17:33:13

5

如果你不想酒意顯示了只使用.tipsy('disable')的元素。

如果您使用的是trigger: manual而您想隱藏它,則可以刪除正文中的.tipsy div。

還有disableenabletoggleEnabled

0

用途:.unbind( '的mouseenter鼠標離開'); 刪除一個醉意的方法。

0

我之前在移動設備上使用谷歌搜索功能禁用Tipsy時發現此問題,原因是觸摸/點擊事件的複雜性,特別是在iPad上。

我決定實施的解決方案是在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(); 
}; 

See: The best way to detect if user agent supports touch

0

更簡單的方法即時通訊使用:

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