5 个答案:
答案 0 :(得分:5)
变化:
.text(title)
到
.html(title)
答案 1 :(得分:4)
使用.html()代替.text()
$(this).hover(function(){
// Hover over code
var title = $(this).find('span').html();
if(title){
$('
.html(title) // Change here
.appendTo('body')
.fadeIn('slow');
}
}, function() {
// Hover out code
$('.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 })
});
答案 2 :(得分:3)
您获取了跨度的html,但随后将其设置为工具提示作为文本。您还需要将其设置为html:
var title = $(this).find('span').html();
if (title) {
$('
.html(title) //
.appendTo('body')
.fadeIn('slow');
}
答案 3 :(得分:3)
将您的JS从.text()更改为.html()。
$(this).hover(function(){
// Hover over code
var title = $(this).find('span').html();
if(title){
$('
// Change the line below!
.text(title) // CHANGE THIS TO `.html(title)`
// ^ Should be .html() [So it parses and renders the HTML]
.appendTo('body')
.fadeIn('slow');
}
}, function() {
// Hover out code
$('.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 })
});
答案 4 :(得分:1)
尝试这样
$(this).hover(function(){
// Hover over code
var title = $(this).find('span').html();
if(title){
$('
.html(title)
.appendTo('body')
.fadeIn('slow');
}}