我正在尝试修改这段代码,以便如果我的链接的title属性为空,那么#tooltip将不会显示:
this.tooltip = function(){
/* CONFIG */
xOffset = -23;
yOffset = -150;
// these 2 variable determine popup's distance from the cursor
// you might want to adjust to get the right result
/* END CONFIG */
$("a.tooltip").hover(function(e){
this.t = this.title;
this.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();
});
$("a.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();
});您可以在此处查看现场示例:http://cssglobe.com/lab/tooltip/01/
我正在尝试在我的CMS中实现这一点。标题属性将通过自定义字段生成。如果没有提供自定义字段内容,则仍然会显示一个空的#工具提示弹出窗口,但如果title attr为空,则我希望删除该弹出窗口。
发布于 2015-01-08 06:57:59
如果根本没有title属性,属性选择器将过滤掉该类中只有title属性的元素
$("a.tooltip[title]").hover(....https://stackoverflow.com/questions/27829920
复制相似问题