【问题标题】:Dynamically change only one element in tooltip title using tooltipster使用 tooltipster 仅动态更改工具提示标题中的一个元素
【发布时间】:2013-10-02 03:14:43
【问题描述】:

我在 tooltipster 标题属性中有一组选项,如下所示:

<i class="icon-cog settings" title="
                   <div class='div1' onclick='follow(1,2)'>Content 1</div>
                   <div class='div2' ...>Content 2</div>
                   <div class='div3' ...>Content 3</div>
                                                   ">
</i>

当点击 div1 时,内容会通过基于以下函数的 ajax 结果动态更新:

function follow(f1,f2) {
$.get('/exe/add_followers.php?f1=' + f1 + '&f2=' + f2, function (result) {
    $('.div'+f2).html('content 1 is updated to' + result.newcontent);
    }, 'json');
}

问题是当tooltip关闭,页面没有刷新时,内容又回到了初始值,而不是显示更新后的值。

我尝试使用Here 所述的配置选项:

function follow(f1,f2) {
    $.get('/exe/add_followers.php?f1=' + f1 + '&f2=' + f2, function (result) {
        // $('.div'+f2).html('content 1 is updated to' + result.newcontent);
        $('.settings').tooltipster('update', 'content 1 is updated to' + result.newcontent);
        }, 'json');
} 

但是,这会更改 div1 的内容,但会删除其他 div 的内容。如何只更新 div1 的内容而保持其他不变?

==EDIT==

我更喜欢不通过所有 div 的解决方案,如下所示:

function follow(f1,f2) {
    $.get('/exe/add_followers.php?f1=' + f1 + '&f2=' + f2, function (result) {
        $('.settings').tooltipster('update', '
                                              <div class='div1' onclick='follow(1,2)'>'+result.newcontent+'</div>
                                              <div class='div2' ...>Content 2</div>
                                              <div class='div3' ...>Content 3</div>
                                             ');
        }, 'json');
}

【问题讨论】:

  • 这是标题属性上引用的问题。
  • @ram 你能详细说明一下吗?请!
  • 尝试使用'和"的组合来转义title属性值,以将html转义为字符串
  • 它确实有效。 html变得一团糟。此外,here 在“在工具提示中使用 HTML 标记”部分中说“在设置属性时使用单引号”。

标签: jquery tooltip tooltipster


【解决方案1】:

我发现这个命令可以改变标题:

$('#selectorElement').tooltipster('content', 'new title');

【讨论】:

  • 你确定它有效吗?因为我得到“Tooltipster:一个或多个工具提示已附加到下面的元素。忽略。”
【解决方案2】:

我意识到从标题属性渲染大量 html 是一种不好的方法!所以,我发现tooltipster不适合我的需求,我开始使用jQuery Bootstrap-style Dropdowns

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    相关资源
    最近更新 更多