2013-02-05 75 views
3

我試圖用我的應用程序中的所有元素替換默認工具提示(title =「*」),該工具提示允許我定義自定義工具提示。用jQuery工具提示替換所有標題的默認工具提示

<div> 
    <input type="text" title="default tooltip" /> 
    <textarea type="text" title="default tooltip"></textarea> 
    <select title="default tooltip"><option>select</option></select> 
</div> 

$(function() { 
$('input, textarea, select, p, label').tooltip({ 
hide: { 
effect: "explode", 
delay: 250 
} 
}); 
}); 

檢查小提琴:http://jsfiddle.net/tnEmZ/1/

+0

你要保持同樣的提示信息爲所有elemnets? – Deadlock

回答

4
var $title = $("a,input,p,label,textarea[title]"); //get all elements with the title-Attribute 

//loop through title-elements 
$.each($title, function(index, value) { 
    $(this).tooltip({ 
     show: { 
      effect: "explode", 
      delay: 250 
     }, 
     hide: { 
      effect: "explode", 
      delay: 250 
     } 
    }); 
}); 

演示here

+0

謝謝!這是真棒:) – BurebistaRuler

+0

thx。它的工作以及jQuery UI部件。 –

1

希望這DEMO會幫助你。

$(document).ready(function() { 
     // Tooltip only Text 
     $('.masterTooltip').hover(function(){ 
       // Hover over code 
       var title = $(this).attr('title'); 
       $(this).data('tipText', title).removeAttr('title'); 
       $('<p class="tooltip"></p>') 
       .text(title) 
       .appendTo('body') 
       .fadeIn('slow'); 
     }, function() { 
       // Hover out code 
       $(this).attr('title', $(this).data('tipText')); 
       $('.tooltip').remove(); 
     }).mousemove(function(e) { 
       var mousex = e.pageX + 20; //Get X coordinates 
       var mousey = e.pageY + 10; //Get Y coordinates 
       $('.tooltip') 
       .css({ top: mousey, left: mousex }) 
     }); 
}); 

又如HEREjquery tooltip

來源:http://jqueryui.com/tooltip/

1

的工具提示部件不是jQuery的,但jQueryUI的一部分。此外,它不會在你的jsfiddle上工作,因爲工具提示widget帶有jQueryUI 1.9.0,而你的jsfiddle使用jQueryUI 1.8.3。有關更多信息,請參閱here