【问题标题】:How to get the text within a span in a tooltip via jQuery?如何通过 jQuery 在工具提示的范围内获取文本?
【发布时间】:2013-08-12 03:40:53
【问题描述】:

我正在尝试使用Tooltipster jQuery plugin 将跨度内的文本作为工具提示的“内容”。

“内容”选项的可用参数的描述可以在这里看到:

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/

解决方案

根据下面的答案,这是我采用的实现方式。下面的 sn-p 显示了 js 解决方案与插件参数的集成:

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

【问题讨论】:

  • 如果您发现答案有用,您介意将其标记为已接受

标签: jquery tooltip tooltipster


【解决方案1】:

试试

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

演示:Fiddle

【讨论】:

  • 此解决方案将&lt;p&gt; 标记内的文本添加到工具提示中。我正在尝试将&lt;span&gt; 标签中的文本添加到工具提示中。
  • @user1063287 你的意思是第二个工具提示,你想显示UNIQUE?喜欢jsfiddle.net/arunpjohny/X88u3/2
  • 对于任何存在关联工具提示的跨度的实例,&lt;span&gt; 标记中的文本应该是工具提示中显示的内容。所以在上面的例子中,第一个工具提示应该是SOME MORE,第二个工具提示应该是UNIQUE
猜你喜欢
  • 2017-10-12
  • 2019-07-23
  • 1970-01-01
  • 2021-07-24
  • 1970-01-01
  • 2019-06-25
  • 2010-11-22
  • 2013-07-25
  • 1970-01-01
相关资源
最近更新 更多