Sweetalert: 如何添加多个文本行?

创建于 2017-10-08  ·  9评论  ·  资料来源: t4t5/sweetalert

你好
我如何制作多行或使用 html
?

最有用的评论

这是我基于https://sweetalert.js.org/docs/#content的 hack

var span = document.createElement("span");
span.innerHTML='abc<br>efg'
swal({
  content: span,
});

我相信有更好的方法。

所有9条评论

这是我基于https://sweetalert.js.org/docs/#content的 hack

var span = document.createElement("span");
span.innerHTML='abc<br>efg'
swal({
  content: span,
});

我相信有更好的方法。

目前, @simon1tan的做法是<br>标签替换\n字符,这样人们就可以写:

swal("Hello\nthere!")

如果有人想解决这个问题(应该很简单),请随时发送拉取请求!

一直很难找到使用HTML元素的方法,你的hack帮助了我,非常感谢你的朋友!

PD:“\n”它对我不起作用,它没有换行

我认为自动事情不太好,我认为是更好的不同选择,例如

  • 内容:当前对象
  • 文本:纯文本(如果您可以在此处添加换行符解析)
  • html: 接收 html 字符串

你可以使用 html 来使用“

swal({
标题:'错误',
html: 'Verifique 赞成 e 意图
asdasdasas' ,
显示确认按钮:真,
显示关闭按钮:真,
})
再见

const lines = ['您对我们非常重要,收到的所有信息将始终保密。', '我们将在审核您的消息后立即与您联系。', '我们已通过 '+contact_email+' 向您发送电子邮件, 请检查它以获得快速响应。'];

swal('感谢您联系我们!',lines.join('\n\n'),'success');

//为我工作!

const lines = ['You are very important to us, all information received will always remain confidential.', 'We will contact you as soon as we review your message.', 'We have sent an email to you at '+contact_email+' , Please check it for quick response.']; swal('Thank you for contacting us!',lines.join('\n\n'),'success');

对于我的情况,添加 div 标签来覆盖文本将起作用

origina: Line0<br />Line1<br /> [not working]
after: <div>Line0<br />Line1<br /></div> [working fine]
swal({
    title: 'Mt Title',
    html: '<div>Line0<br />Line1<br /></div>',
 });

swal({ buttons: ["Wait ", "Add Details"], html: true, text: "Text one .\n Text 2.\n Text 3." })
这是解决方案。 在反应中完美地工作。 享受

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

daftspunk picture daftspunk  ·  4评论

vmitchell85 picture vmitchell85  ·  6评论

voodoo6 picture voodoo6  ·  4评论

waldyrious picture waldyrious  ·  5评论

xgqfrms-GitHub picture xgqfrms-GitHub  ·  4评论