javascript 在引导弹出窗口内容中将文本分成多行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25739024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Break text to multiple lines in bootstrap popover content
提问by Saqib
I am trying to add text content of bootstrap popover
with multiple lines. I am creating string with possible line break as below, I have tried \n, \r\n, <br>, <br/> and <br />
but all vain.
我正在尝试添加bootstrap popover
多行的文本内容。我正在创建可能有换行符的字符串,如下所示,我已经尝试过,\n, \r\n, <br>, <br/> and <br />
但都是徒劳的。
var files = 'No files selected';
if (path.length > 1) {
files = '';
for (var i = 0; i < path.length - 1; i++) {
files += path[i] + '<br />';
}
}
$(this).attr('data-content', files);
$(this).popover('toggle');
from above code what input do I get in popover is shown below
从上面的代码我在弹出窗口中得到的输入如下所示
I have read in some posts to add / update popover
contents through content tag but didn't work. Plus there was a post to set HTML
content for the popover
which I didn't get. I don't know what to do to create new lines by using above method or similar one.
我读过一些帖子,popover
通过内容标签添加/更新内容,但没有用。再加上有一个帖子,以集HTML
的内容popover
,我没有得到。我不知道如何使用上述方法或类似方法创建新行。
回答by Anticom
You could either add data-html="true" or do that in JS. For the JS solution please refer to How do you add line break to JQuery popover.
您可以添加 data-html="true" 或在 JS 中执行此操作。JS 解决方案请参考How do you add line break to JQuery popover。
回答by Gurpreet Singh
You need to pass the option HTML: true when you initialize the popover. Then
and other HTML tags should work:
您需要在初始化弹出窗口时传递选项 HTML: true 。然后
和其他 HTML 标签应该可以工作:
$(".foo").hover(function () {
$(this).popover({
title: "Bar",
content: "Line 1 <br /> Line 2 <br /> Line 3",
html: true
}).popover('show');
}, function () {
$(this).popover('hide');
});