Jquery工具提示,从其他属性获取数据

问题描述 投票:0回答:3

由于我的页面有其他jquery插件使用title属性,所以我的jquery工具提示可以从“title”以外的其他属性获取数据吗? http://flowplayer.org/tools/tooltip/index.html#configuration

<span class="something" title="This is title" otherattr="This is the tooltips"></span>
jquery tooltip jquery-tooltip
3个回答
1
投票

如果我正确理解了jTools Tooltip文档,如果你通过选择器设置工具提示,然后是$(“[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(); 
});

0
投票

您可以将函数指定为工具提示的内容,并以编程方式从属性中获取内容。在这种情况下,您需要属性'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()}

所以只需编写自己的而不是使用默认函数。希望有所帮助!


0
投票

$(".something").tooltip({
    items: '[otherattr]',
    content: function(){ 
        return $(this).attr("otherattr"); 
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.