如何在甜蜜警报中使用html标签

时间:2017-05-05 05:40:55

标签: jquery jquery-plugins

var text += '<b>Hii This is Error<b>';
swal("Required", text, "error");

如何在Bootstrap Sweet警报插件中使用html编码。

在上面的代码中,我必须写一个一条错误消息!来在sweetalert中显示。但是在文本变量中使用html标签时,它需要字符串, 并且可以在sweetalert中显示相同的字符串,它不能在html标签中转换。

3 个答案:

答案 0 :(得分:0)

您必须添加html:true才能显示HTML内容,例如

swal({
  title: "Required",
  text: "<b>Hii This is Error<b>",
  html: true, // add this if you want to show HTML
  type: "error" // type can be error/warning/success
});

阅读Sweetalert configuration

答案 1 :(得分:0)

你应该试试这个

swal({   
    title: "Error",  
    text: '<b>Hii This is Error<b>',
    html: true 
});

Sweet alert documentation

答案 2 :(得分:0)

在SweetAlert 2.0中,您不能使用html标记, 他们在他们的guide中提到了这一点。

我使用过的SweetAlert 2.0可以做到这一点,并且对我有用,它是创建html作为内容对象并将其传递给swal like here或以下示例。

HTML内容

var htmlContent = document.createElement("div");
htmlContent.innerHTML = "Create your html the way you want just as usual in 
<strong>JavaScript</strong> code.";

小狼

swal({
    title: "You did it.",
    content: htmlContent,
    icon: "warning",
    ...
})