我.html()
用于获取 a 的内容span tag
并将其显示为工具提示,但 span 标签内的 html 标签直接显示在工具提示内,无需渲染。
<div>
<a href="#">Parent
<span>
<strong>It is a long established</strong> The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to usi<em>ng 'Content here, content here', m</em>aking it look like readable English. Many desktop publishing packages
</span>
</a>
</div>
JavaScript
$(this).hover(function(){
// Hover over code
var title = $(this).find('span').html();
if(title){
$('<p class="tooltip"></p>')
.text(title)
.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 })
});
小提琴:http: //jsfiddle.net/qA88d/