Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在sweetalert JavaScript中格式化字符串_Javascript_Sweetalert_Sweetalert2 - Fatal编程技术网

在sweetalert JavaScript中格式化字符串

在sweetalert JavaScript中格式化字符串,javascript,sweetalert,sweetalert2,Javascript,Sweetalert,Sweetalert2,我有API返回我这个字符串: string.Format( "Something went wrong with {0}." + "<br>" + " Do you want to continue with?" + "<strong>" + "{1}" + "</strong>", ); 我想

我有API返回我这个字符串:

string.Format(
  "Something went wrong with {0}." +
    "<br>" +
    " Do you want to continue with?" +
    "<strong>" +
    "{1}" +
    "</strong>",
);

我想把第二个短语放在第一个下面,最后一个单词应该是粗体的

有什么建议可以解决这个问题吗


提前谢谢

您正在使用旧版本的sweetalert

查看更多信息:

//首先,检查它是否尚未实现。
if(!String.prototype.format){
String.prototype.format=函数(){
var args=参数;
返回此。替换(/{(\d+)}/g,函数(匹配,编号){
返回参数的类型[编号]!=“未定义”
?args[编号]
:匹配
;
});
};
}
var mess=“{0}出现问题。\n是否继续使用{1}?”.format(“Macchina”、“carrello”);
泥泞{
heightAuto:false,
标题:“Richiesta Disconessione”,
图标:“警告”,
按钮:{
取消:{
文本:“否”,
值:null,
可见:对,
类名:“甜蜜的取消”,
对,,
},
确认:{
文本:“是”,
价值观:正确,
可见:对,
类名:“甜确认”,
真的吗
}
}
})
.sweet confirm{color:#3085d6;}
.sweet cancel{color:#d33;}

您能否通过硬编码Swal.fire()调用来实现所需的结果?我的猜测是API中返回的错误被转义了。它是相同的,没有什么变化,正如您从我的代码片段中看到的,它是不同的
var mess = "@messaggio";
Swal.fire({
  heightAuto: false,
  title: "Richiesta Disconnessione",
  html: mess,
  icon: "warning",
  showCancelButton: true,
  confirmButtonColor: "#3085d6",
  cancelButtonColor: "#d33",
  confirmButtonText: "Yes",
  cancelButtonText: "No",
});