sweetalert2具有相同功能的多个swal [英] sweetalert2 multiple swal at the same function

查看:464
本文介绍了sweetalert2具有相同功能的多个swal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个条件,并为每只猫叫一只小狼(Sweetalert2).但是只有一只小马奔跑.我该怎么办?

I'd like to make a condition and call a swal for each one (Sweetalert2). But only one of the swal runs. How can I do it?

function validateEmail(email) {
  var regex = /\S+@\S+\.\S+/;
  return regex.test(email);
}

function validateBirth(data) {
  var regex = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
  return regex.test(data);
}

function validacao() {
  var data = document.getElementById('birth').value;
  var email = document.getElementById('email').value;
  if (!validateBirth(data)) {
    swal(
      'title..',
      'text..',
      'type..'
    );
  }
  if (!validateEmail(email)) {
    swal(
      'title..',
      'text..',
      'type..'
    );
  }
}

推荐答案

swal.queue() ,将其用于多种模式.

There's swal.queue(), use it for multiple modals.

您的情况应如下所示:

var modals = [];

// birth modal
if (!validateBirth(data)) {
  modals.push({title: 'title1', text: 'text1', ... });
}

// email modal
if (!validateEmail(email)) {
  modals.push({title: 'title2', text: 'text2', ... });
}

swal.queue(modals);

这篇关于sweetalert2具有相同功能的多个swal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆