由于我的页面有其他使用 title 属性的 jquery 插件,所以我的 jquery 工具提示可以从“title”以外的其他属性获取数据吗? http://flowplayer.org/tools/tooltip/index.html#configuration
<span class="something" title="This is title" otherattr="This is the tooltips"></span>
由于我的页面有其他使用 title 属性的 jquery 插件,所以我的 jquery 工具提示可以从“title”以外的其他属性获取数据吗? http://flowplayer.org/tools/tooltip/index.html#configuration
<span class="something" title="This is title" otherattr="This is the tooltips"></span>
如果我正确理解 jTools 工具提示文档,如果您通过 $("[title]") 以外的选择器设置工具提示,它将使用紧跟在触发器后面的元素作为工具提示内容。
所以你可以做这样的事情:
$(document).ready(function(){
//place a span with class tooltip after each element with otherattr attribute placing the otherattr text inside it
$("[otherattr]").each(function(){
$(this).after('<span class="tooltip">' + $(this).attr("otherattr") + '</span>');
});
//when we initate the tooltip this way it will use the .tooltip span after each element.
$("[otherAttr]").tooltip();
});
您可以将函数指定为工具提示的内容,并以编程方式从属性中获取内容。在这种情况下,您需要属性“otherattr”,因此您可以尝试以下操作:
$(".something").tooltip({
"content": function(){
return $(this).attr("otherattr");
}
});
我不得不挖掘一些源代码来弄清楚这一点,默认情况下,可以通过以下方式找到工具提示的“内容”
$(".something").tooltip("option", "content")
并看到它返回:
function (){var e=t(this).attr("title")||"";return t("<a>").text(e).html()}
所以只需编写你自己的而不是使用默认函数。希望有帮助!
$(".something").tooltip({
items: '[otherattr]',
content: function(){
return $(this).attr("otherattr");
}
});