ajax HTML内容未在bootstrap pop中呈现
ajax HTML content not rendering in bootstrap pop
我正试图从ajax请求中获取HTML内容,以加载到twitter引导程序(v3)popover中。
popover元素看起来是这样的。
<a class="more-info" data-remotecontent="/tasks/moreinfo/56eb0256-1a78-483c-b053-a387011f5b97" data-original-title="task 1" data-title="task 1" data-toggle="popover" rel="popover" href="/tasks/56eb0256-1a78-483c-b053-a387011f5b97">task 1</a>
javascript看起来是这样的。
$('a.more-info').each(function () {
var info = $(this);
info.bind('mouseenter', function () {
info.popover({
html: true,
title: info.html(),
content: 'Loading',
}).popover('show');
$.get(info.attr('data-remotecontent'), function (data) {
}).done(function (data) {
info.attr('data-html', 'true');
//info.popover({ content: data, placement: 'right' }).popover('show');
info.attr('data-placement', 'right');
info.attr('data-content', data);
info.popover('show');
});
});
info.bind('mouseleave', function () {
info.popover('hide');
});
});
ajax get请求返回HTML,但它从未被呈现到popover中。我有一种感觉,我可能无法正确地逃离响应字符串。
要将ajax响应呈现到popover的内容中,我缺少什么?
如果没有向已经初始化的popover
注入新内容的引导方法,则必须操作生成的标记,如下所示这不是一个理想的解决方案。我建议在收到ajax内容后调用destroy
方法一次,更新元素,初始化并以编程方式打开popover
A。操作popover标记——不好
以下是popover标记的样子:
<div class="popover fade right" role="tooltip" ....>
<div class="arrow" style="top: 12.987012987013%;"></div>
<h3 class="popover-title">task 1</h3>
<div class="popover-content">Loading</div>
</div>
注意:这不是一个好的解决方案的主要原因是不能保证这将是未来版本中的标记
概念验证
B。调用destroy方法,初始化并打开--GOOD
概念验证
此外,如果希望每个mouseenter
事件产生相同的Loading ..
效果,则mouseleave
处理程序必须再次销毁popover并对其进行初始化。
info.bind('mouseleave', function () {
info.popover('destroy')
.popover({
html: true,
title: info.html(),
content: 'Loading',
});
});
相关文章:
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- 浮动页脚栏-使用Bootstrap隐藏
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 我想使用模态通过php文件发送邮件,并且我希望在提交关闭后关闭pop
- 创建带有和不带有JavaScript的Bootstrap下拉菜单
- AngularJS/HTML/Bootstrap元素用于动态搜索结果
- Javascript+Bootstrap图像库未加载
- Bootstrap Dropdown selection是在*all*下拉菜单上设置选择
- Bootstrap 3 Datepicker v4:dp.show和dp.change事件在Datepicker内联时不
- Bootstrap-三列相等;t更改'a'要素
- 在bootstrap中显示隐藏特定的li
- 为什么引导程序下拉菜单只有在包含bootstrap-responsive.css时才起作用
- Twitter Bootstrap 2.1.0子菜单在Responsive上看起来很混乱
- Bootstrap折叠按钮不适用于android
- bootstrap消除模态并显示另一个模态
- Bootstrap下拉菜单不起作用
- 如何移除或改进:在Bootstrap Carousel上聚焦风格
- 在BootStrap菜单栏中为所选项目设置背景,类似于BootStrap中的父导航选项
- 如何获得Bootstrap Datepicker的年和月,因为它在变化
- ajax HTML内容未在bootstrap pop中呈现