\ n以及<br> JavaScript警报中的新行均不起作用

我正在使用JavaScript警报(尽管稍作修改)。该警报具有标题字段和内容字段。在我的内容字段中,我想在换行中显示一些文本,但是\n<br>都不起作用。参见图片以检查给定代码的输出。

new Attention.Alert({
                title: 'School',content: 'Date - '+v_date+'\n School Name - '+ school_name + "\n School City - " + school_city + " "
            });

\ n以及<br> JavaScript警报中的新行均不起作用

blackless 回答:\ n以及<br> JavaScript警报中的新行均不起作用

您只需为弹出式内容添加CSS white-space: pre-line;

这里是示例。

jQuery(document).ready(function($) {
  $('button').click(function(e){
    e.preventDefault();
    var v_date = '04/11/2019';
    var school_name = 'School Name';
    var school_city = 'School City';
    new Attention.Alert({
        title: 'This is a Title',content: 'Date - '+v_date+'\n School Name - '+school_name+'\n School City - '+school_city
    });
  });
});
*,*:after,*:before{
	box-sizing: border-box;
}
body {
	font-family: 'Open Sans',serif;
	background-color: #d1d8de;
	padding: 20px;    
}
.attention-component .inner-container p{
    white-space: pre-line;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://janmarkuslanger.github.io/attention.js/dist/attention.js"></script>
<link href="https://janmarkuslanger.github.io/attention.js/dist/attention.css" rel="stylesheet">
<button>Click</button>

本文链接:https://www.f2er.com/3168610.html

大家都在问