微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我想在另一个成功警报之后使用“甜蜜警报”显示输入警报,并且我想为其签名一个函数,该函数将检查写入的值是否与名为“codeNumber”的给定值匹配,该值基本上是一个 PHP变量。
回声' swal({ 图标:“成功”, title: "我们给你发了一封邮件!",text: "一封包含 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(/* ... /*)

您想要的是对 .then() 的结果调用 swal()

swal({
  title: "Write the 6-digits code here.",}).then((inputValue) => { // notice the closing parenthesis before .then()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。