我希望能够创建一个工具提示,但是要从两个不同的地方进行引用
this.tooltip = function(){
xOffset = 10;
yOffset = 20;
$("div.tooltip").hover(function(e){
this.t = $("a.tooltip").title;
$("a.tooltip").title = "";
$("body").append("<p id='tooltip'>"+ this.t +"</p>");
$("#tooltip")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
$("#tooltip").remove();
});
$("div.tooltip").mousemove(function(e){
$("#tooltip")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
};
// starting the script on page load
$(document).ready(function(){
tooltip();
});
这是我希望能够与之合作的地方。我有一个文本“滚动到工具提示”,然后会弹出一个框,上面写着“Web Standards Magazine”。
<div class="tooltip">Roll over for tooltip</div>
<span class="tooltip" title="Web Standards Magazine"></a>
我知道有一些方法可以让你只拥有一个区域,比如
<span class="tooltip" title="Web Standards Magazine">Roll over for tooltip</a>
我不这样做的原因是因为我正在处理一个较大文件的一小部分,我不想搞砸任何事情。
我得到了 undefined variable 。需要帮助,谢谢!
最佳答案
假设您正在做一些类似 hover()
的事件,您可以连接 class
接收到事件的元素的 id-selector
[docs]以便选择相应的<div>
.
$('img[class^="tooltip"]').hover(function() {
$('#' + this.className).fadeIn(); // fadeIn, or do whatever with the div
},
function() {
$('#' + this.className).fadeOut(); // fadeOut, or do whatever with the div
});
关于jquery - 如何引用两个不同的标签?使用工具提示!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6416962/