我在使用 Javascript 和 PHP 将函数分配给 SweetAlert 时出错



我想在另一个成功警报之后使用"sweet alert"来显示一个输入警报,并且我想为它签名一个函数,该函数将检查写入的值是否与名为"的给定值匹配;codeNumber";它基本上是一个PHP变量
echo'洼地({图标:";"成功";,标题:";我们给你发了一封电子邮件&";,文本:";已经向您发送了一封包含6位代码的电子邮件&";,});

swal({
title: "Write the 6-digits code here.",
text: "Code:",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
}.then((inputValue) => {
var rightcode = ' . $codeNumber . ';
if (inputValue === null) {return false};
if (inputValue === ""){
swal.showInputError("You need to write something!");
return false
}
if(inputValue === rightcode){
swal({
icon: "success",
title: "Registred successfully!",
text: "your account has been created!"
});
}
if(inputValue !== rightcode){
swal.showInputError("Wrong code!")
return false;
}
}));;
</script>
';

错误代码:
{(intermediate value)(intermediate value)(intermediate value)(intermediate value)(intermediate value)(intermediate value)}.then is not a function

你的括号搞砸了。您在对象文字上调用.then()

{
title: "Write the 6-digits code here.",
text: "Code:",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
}.then(/* ... /*)

您想要的是根据swal():的结果调用.then()

swal({
title: "Write the 6-digits code here.",
text: "Code:",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
}).then((inputValue) => { // notice the closing parenthesis before .then()

最新更新