[英]Javascript/Jquery: How do I modify this script to avoid have to use a <A> tag?
One of the issues I have with this script is that I have to have a link tag to get the rel
from it. 这个脚本的问题之一是,我必须具有一个链接标记才能从中获得rel
。 I am looking at doing descriptions when user mouseover's a table row. 当用户将鼠标悬停在表行上时,我正在查看说明。
What I need: If TD has desc
, append text. 我需要什么:如果TD具有desc
,请添加文本。 <td desc="blah blah blah">
this.screenshotPreview = function () {
xOffset = 20;
yOffset = 30;
$("tr:has(a[desc])").hover(function (e) {
var text = $(this).find('a').attr('desc');
$("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();
});
JSFIDDLE: http://jsfiddle.net/zD99p/1/ (in jsfiddle, it still uses rel
instead of desc
. You can code it either way, I can change that with no problem) JSFIDDLE: http : //jsfiddle.net/zD99p/1/ (在jsfiddle中,它仍然使用rel
而不是desc
。您可以用任何一种方式进行编码,我可以毫无问题地进行更改)
You can use data-
attributes: 您可以使用data-
属性:
http://jsfiddle.net/MWkXJ/ http://jsfiddle.net/MWkXJ/
<td data-desc="..."></td>
$("td[data-desc]").hover(function (e) {
var text = $(this).data('desc');
//...
Maybe something like this: 也许是这样的:
...
$("td[desc]").hover(function (e) {
var text = $(this).attr('desc');
$("body").append("<p id='screenshot'>" + text + "</p>");
...
And change html to this: 并将html更改为此:
<td desc="blah blah">content ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.