如何通过jQuery在工具提示中获取跨度内的文本? [英] How to get the text within a span in a tooltip via jQuery?

查看:61
本文介绍了如何通过jQuery在工具提示中获取跨度内的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Tooltipster jQuery插件将范围内的文本作为工具提示的内容" .

I am trying to get the text within a span to be the 'content' of a tooltip using the Tooltipster jQuery plugin.

有关内容"选项可用参数的说明,请参见此处:

A description of the available parameters for the 'content' option can be seen here:

http://calebjacob.com/tooltipster/#options

JQuery

<script type="text/javascript">
$(document).ready(function() {
$('.tooltip').tooltipster({
content: $(this).parent().text() // trying to get the span text here
});
});
</script>

HTML

<p>Here is some text, and here is <span class="tooltip" data-rlink="<a href=&quot;http://www.google.com&quot;>a link</a>">SOME MORE</span> text.</p>
<p>And the content should be <span class="tooltip">UNIQUE</span> to the instance.</p>

jsFiddle

http://jsfiddle.net/rwone/y9uGh/1/

解决方案

基于以下答案,这是我所采用的实现.下面的代码片段显示了js解决方案与plugins参数的集成:

Based on the answer below, this was the implementation I went with. The snippet below shows integration of the js solution with the plugins parameters:

<script type="text/javascript">
$(document).ready(function() {
$('.tooltip').tooltipster({
functionBefore: function(origin, continueTooltip){
origin.tooltipster('update', $(origin).text());
continueTooltip();
},
animation: 'grow',
arrow: false,
});
});
</script>

推荐答案

尝试

$(document).ready(function() {
    $('.tooltip').tooltipster({
        functionBefore: function(origin, continueTooltip){
            origin.tooltipster('update', $(origin).text());
            continueTooltip();
        }
    });
});

演示:小提琴

这篇关于如何通过jQuery在工具提示中获取跨度内的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆