【问题标题】:Chaining sweetalert2 modals链接 sweetalert2 模态
【发布时间】:2016-08-17 00:40:12
【问题描述】:

我正在使用 sweetalert2 验证电子邮件地址,但我希望它随后显示一个文本输入以供输入名称。我知道它链接了模式,但我一生都无法从页面上给出的示例中弄清楚如何?

var cloud_email = $('.cloud_email').text();
var user_name = $('.user_name').text();;
swal.setDefaults({
  confirmButtonText: 'Next →',
  showCancelButton: true,
  animation: false
});

var steps = [
  {
    //ask for and validate email here
    type: 'question',
    title: 'Please enter email address',
    input: 'email',
    inputValue: cloud_email  
  },
  {
    //ask for and validate text input here
    type: 'question',
    title: 'Please enter user name',
    input: 'text',
    inputValue: user_name
  }
];

swal.queue(steps).then(function(email, name) {
  swal({
    type: 'success',
    html: 'Email successfully sent to: ' + name + ': '+ email
  });
}).finally(function() {
  swal.resetDefaults();
  //ajax to process values passed
})

我的尝试返回此错误:

swal.queue(...).then(...).finally is not a function

【问题讨论】:

    标签: javascript promise sweetalert finally sweetalert2


    【解决方案1】:

    要使用finally() 方法,您应该在页面中包含polyfill for Promise.prototype.finally,例如:

    <script src="https://cdn.jsdelivr.net/promise.prototype.finally/1.0.1/finally.js"></script>
    

    PS。我刚刚将Promise.prototype.finally polyfill 的链接添加到示例页面:https://sweetalert2.github.io/#chaining-modals

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-06
      • 2020-06-26
      • 1970-01-01
      相关资源
      最近更新 更多