swal弹窗,sweetalert2具有相同功能的多个swal[通俗易懂]

2022-11-17 13:21:06 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

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..’

);

}

}

解决方案

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

Your case should look like this:

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);

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

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/234921.html原文链接:https://javaforall.cn

0 人点赞