\n 以及 <br> 中的新行 JavaScript 警报不起作用
\n as well as <br> for new line in JavaScript alert not working
我正在使用 JavaScript 警报(虽然稍作修改)。此警报有一个标题字段和一个内容字段。在我的内容字段中,我想在新行中显示一些文本,但 \n
和 <br>
都不起作用。查看图像以检查给定代码的输出。
new Attention.Alert({
title: 'School',
content: 'Date - '+v_date+'\n School Name - '+ school_name + "\n School City - " + school_city + " "
});
您只需为弹出内容添加 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>
我正在使用 JavaScript 警报(虽然稍作修改)。此警报有一个标题字段和一个内容字段。在我的内容字段中,我想在新行中显示一些文本,但 \n
和 <br>
都不起作用。查看图像以检查给定代码的输出。
new Attention.Alert({
title: 'School',
content: 'Date - '+v_date+'\n School Name - '+ school_name + "\n School City - " + school_city + " "
});
您只需为弹出内容添加 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>