当前位置: 代码迷 >> JavaScript >> 为什么警报的换行符不起作用?
  详细解决方案

为什么警报的换行符不起作用?

热度:77   发布时间:2023-06-05 14:04:56.0

我正在使用alertable.js 。 当我尝试换行时,它不起作用。

我尝试:

$.alertable.confirm('Line1\nLine2').then(function() {
  //ok
}, function() {
  //not     
});

您输入confirm的字符串就是显示为HTML的字符串。 在HTML中, \\n不会解析为换行符,因此可以正常显示。

相反,如果将设置为true,则可以像这样使用HTML中断标签<br /> :

$.alertable.confirm('Line1<br />Line2', {
  html: true
}).then(function() {
  //ok
}, function() {
  //not     
});

在查看工作示例

尝试将message选项设置为html并在新行中插入<br/>标记而不是\\n :

$.alertable.confirm('Line1 <br/> Line2', {
  html: true,
}).then(function() {
    //ok
}, function() {
    //not     
});

您可以在此处参考文档: :

  相关解决方案