Twitter bootstrap 是否可以使用div作为Twitter的内容';爆米花
我正在使用twitter的bootstrap的popover。现在,当我滚动浏览popover文本时,会出现一个popover,其中只包含Twitter bootstrap 是否可以使用div作为Twitter的内容';爆米花,twitter-bootstrap,popover,Twitter Bootstrap,Popover,我正在使用twitter的bootstrap的popover。现在,当我滚动浏览popover文本时,会出现一个popover,其中只包含首先,如果要在内容中使用HTML,需要将HTML选项设置为true: $('.danger').popover({ html : true}); 然后您有两个选项来设置Popover的内容 使用“数据内容”属性。这是默认选项 使用自定义JS函数返回HTML内容 使用数据内容: 您需要转义HTML内容,如下所示: 您可以手动转义HTML,也可以使用函数
首先,如果要在内容中使用HTML,需要将HTML选项设置为true:
$('.danger').popover({ html : true});
然后您有两个选项来设置Popover的内容
- 使用“数据内容”属性。这是默认选项
- 使用自定义JS函数返回HTML内容
您可以手动转义HTML,也可以使用函数。我不知道PHP,但在Rails中我们使用*html\u safe*
使用JS函数:
如果你这样做,你有几个选择。我认为最简单的方法是将div内容隐藏在任何你想隐藏的地方,然后编写一个函数将其内容传递给popover。大概是这样的:
$(文档).ready(函数(){
$('.danger').popover({
是的,
内容:函数(){
返回$('#popover_content_wrapper').html();
}
});
});
然后您的HTML如下所示:
这是您的div内容
希望有帮助
PS:我在使用popover时遇到了一些麻烦,没有设置标题属性。。。因此,请记住始终设置标题。如果您只想拥有弹出的外观,请选择另一种替代方法。方法如下。当然,这是一个手动操作,但很好地可行:) HTML-按钮
<button class="btn btn-info btn-small" style="margin-right:5px;" id="bg" data-placement='bottom' rel="tooltip" title="Background Image"><i class="icon-picture icon-white"></i></button>
基于jävi的答案,这可以在没有ID或其他按钮属性的情况下完成,如:
Pop me
我的第一个popover内容在这里。
抓住我
我的第二个popover内容在这里。
抓住我
我的第三个popover内容在这里。
$('.popper').popover({
容器:'主体',
是的,
内容:功能(){
返回$(this.next('.popper content').html();
}
});
晚会迟到了。以其他解决方案为基础。我需要一种将目标DIV作为变量传递的方法。这就是我所做的
Popover源的HTML(添加了一个数据属性数据pop,该属性将保存目标DIV id/或class的值):
除其他答复外。如果您在选项中允许
html
,您可以将jQuery
对象传递给内容,它将与所有事件和绑定一起附加到popover的内容中。以下是源代码中的逻辑:
- 如果传递函数,将调用该函数以展开内容数据
- 如果不允许使用
,则内容数据将作为文本应用html
- 如果允许
且内容数据为字符串,则将作为html
html
- 否则,内容数据将附加到popover的内容容器中
$(“#弹出按钮”).popover({
内容:$(“popover内容”),
是的,
标题:“Popover标题”
});
这里是另一个例子
为什么这么复杂?就这样说吧:
data-html='true'
所有这些答案都忽略了一个非常重要的方面强> 通过使用.html或innerHtml或outerHtml,您实际上并没有使用引用的元素。您正在使用元素html的副本。这有一些严重的倒退
仅供参考,bootstrap有一个名为“hide”的类,它设置display:none只是一个注释,但这种方法对于IE7来说速度非常慢,可能是因为html的副本涉及大量DOM操作。根据我们的经验,它在IE7中不可用,因此您需要以另一种方式进行绑定。如果您发现需要将某些javascript函数附加到
popover\u content\u包装中的链接上,此解决方案将导致问题,因为它将被呈现为html(没有处理程序)。然后,解决方案是侦听“inserted.bs.popover”事件,并将处理程序重新附加到DOM中的新元素。这对我来说是可行的,尽管我必须硬连接popover的位置,这不是很好,例如使用样式=顶部:200px;左:90px
到bgform
div。有没有办法调用bootstrap的自动放置代码?此外,您可以在javascript中使用fadeToggle()或toggle()实现不同的效果。这是唯一正确的方法。html()创建一个副本,使其无法用于数据绑定目的。也没有用于挂接到预转换状态的事件,因此在它可见之前,您无法绑定到popover。您可以添加小提琴吗?这不是开箱即用的。请解释并添加小提琴或完整代码。这是没有帮助的。如果我能把这个投票提高100倍,我会的。我一直在追根究底,试图弄明白为什么在弹出窗口中调用$('#'+id).val()时总是返回一个空白字符串。这是因为该死的html复制了div。
<div class="bgform popover fade bottom in">
<div class="arrow"></div>
..... your code here .......
</div>
$("#bg").click(function(){
$('.bgform').slideToggle();
});
<button class="popper" data-toggle="popover">Pop me</button>
<div class="popper-content hide">My first popover content goes here.</div>
<button class="popper" data-toggle="popover">Pop me</button>
<div class="popper-content hide">My second popover content goes here.</div>
<button class="popper" data-toggle="popover">Pop me</button>
<div class="popper-content hide">My third popover content goes here.</div>
$('.popper').popover({
container: 'body',
html: true,
content: function () {
return $(this).next('.popper-content').html();
}
});
<div data-html="true" data-toggle="popover" data-pop="popper-content" class="popper">
<div id="popper-content" class="hide">Content goes here</div>
$('.popper').popover({
placement: popover_placement,
container: 'div.page-content',
html: true,
trigger: 'hover',
content: function () {
var pop_dest = $(this).attr("data-pop");
//console.log(plant);
return $("#"+pop_dest).html();
}});
here is an another example
<a data-container = "body" data-toggle = "popover" data-placement = "left"
data-content = "<img src='<?php echo baseImgUrl . $row1[2] ?>' width='250' height='100' ><div><h3> <?php echo $row1['1'] ?></h3> <p> <span><?php echo $countsss ?>videos </span>
<span><?php echo $countsss1 ?> followers</span>
</p></div>
<?php echo $row1['4'] ?> <hr><div>
<span> <button type='button' class='btn btn-default pull-left green'>Follow </button> </span> <span> <button type='button' class='btn btn-default pull-left green'> Go to channel page</button> </span><span> <button type='button' class='btn btn-default pull-left green'>Close </button> </span>
</div>">
<?php echo $row1['1'] ?>
</a>
data-html='true'
<h1> Test </h1>
<div><button id="target">click me</button></div>
<!-- This will be the contents of our popover -->
<div class='_content' id='blah'>
<h1>Extra Stuff</h1>
<input type='number' placeholder='number'/>
</div>
$(document).ready(function() {
// We don't want to see the popover contents until the user clicks the target.
// If you don't hide 'blah' first it will be visible outside of the popover.
//
$('#blah').hide();
// Initialize our popover
//
$('#target').popover({
content: $('#blah'), // set the content to be the 'blah' div
placement: 'bottom',
html: true
});
// The popover contents will not be set until the popover is shown. Since we don't
// want to see the popover when the page loads, we will show it then hide it.
//
$('#target').popover('show');
$('#target').popover('hide');
// Now that the popover's content is the 'blah' dive we can make it visisble again.
//
$('#blah').show();
});