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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 04:56:17  来源:igfitidea点击:

Break text to multiple lines in bootstrap popover content

javascriptjquerytwitter-bootstrap-3popover

提问by Saqib

I am trying to add text content of bootstrap popoverwith 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

从上面的代码我在弹出窗口中得到的输入如下所示

enter image description here

在此处输入图片说明

I have read in some posts to add / update popovercontents through content tag but didn't work. Plus there was a post to set HTMLcontent for the popoverwhich 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');
});