【发布时间】: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