js sweetalert实现输入验证码并且判断输入的是否为111111
时间: 2024-02-18 11:04:03 浏览: 20
你可以使用 SweetAlert2 库中的 input 功能来实现输入验证码的弹窗,然后通过 preConfirm 函数来判断输入的验证码是否为 `111111`。下面是一个示例代码:
```javascript
Swal.fire({
title: '请输入验证码:',
input: 'text',
inputAttributes: {
autocapitalize: 'off'
},
showCancelButton: true,
confirmButtonText: '确认',
showLoaderOnConfirm: true,
preConfirm: (code) => {
return new Promise((resolve) => {
setTimeout(() => {
if (code === '111111') {
resolve()
} else {
Swal.showValidationMessage('验证码错误')
}
}, 1000)
})
},
allowOutsideClick: () => !Swal.isLoading()
}).then((result) => {
if (result.value) {
Swal.fire({
title: '验证码输入正确!',
icon: 'success'
})
}
})
```
这段代码会弹出一个输入框,要求用户输入验证码,如果输入的验证码是 `111111`,则提示验证成功,否则提示验证失败。