我有以前的jsfiddle。现在,如果你将鼠标悬停在“测试”上,你会看到一个方块。你会注意到在html中,用于测试的<a>
没有rel。如果没有rel,我会添加什么来阻止在文本上附加,但如果找到rel仍然会附加?
代码:
this.screenshotPreview = function(){
xOffset = 20;
yOffset = 30;
$("tr").hover(function(e){
var text = $(this).find('a').attr('rel');
$("body").append("<p id='screenshot'>"+ text +"</p>");
$("#screenshot")
.css("top",(e.pageY - yOffset) + "px")
.css("left",(e.pageX + xOffset) + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
$("#screenshot").remove();
});
$("a.screenshot").mousemove(function(e){
$("#screenshot")
.css("top",(e.pageY - yOffset) + "px")
.css("left",(e.pageX + xOffset) + "px");
});
};
// starting the script on page load
$(document).ready(function(){
screenshotPreview();
});
HTML:
<table>
<tr><td>content<a rel="Testing this out. This could be a long description. Blah blah blah. Testing this out. Testing this out. This could be a long description. Blah blah blah. Testing this out. " ></td></tr>
<tr><td><a>Testing</a></td></tr>
<table>
答案 0 :(得分:2)
答案 1 :(得分:0)
尝试使用此悬停:
$("tr").hover(function(e){
var text = $(this).find('a').attr('rel');
if ($.trim(text) === '') return;//exit if no text for append
$("body").append("<p id='screenshot'>"+ text +"</p>");
$("#screenshot")
.css("top",(e.pageY - yOffset) + "px")
.css("left",(e.pageX + xOffset) + "px")
.fadeIn("fast");
},
function(){
if (!this.t) return;
this.title = this.t;
$("#screenshot").remove();
});