我可以将 inputType 设置为密码。支持的其他输入类型是什么..?
swal({
title: "Are you sure?",
type: "input",
inputType: "checkbox",
showCancelButton: true,
closeOnConfirm: true,
}, function () {
swal("", "You did it", "success");
});
Run Code Online (Sandbox Code Playgroud)
swal 中不支持复选框 inputType。
Lim*_*nte 10
checkbox在SweetAlert2 中有一种使用模态类型的好方法:
Swal.fire({
title: 'Do you have a bike?',
input: 'checkbox',
inputPlaceholder: 'I have a bike'
}).then((result) => {
if (result.isConfirmed) {
if (result.value) {
Swal.fire({icon: 'success', text: 'You have a bike!'});
} else {
Swal.fire({icon: 'error', text: "You don't have a bike :("});
}
} else {
console.log(`modal was dismissed by ${result.dismiss}`)
}
})Run Code Online (Sandbox Code Playgroud)
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>Run Code Online (Sandbox Code Playgroud)
附注。注意 SweetAlert2 和 SweetAlert 有点不同,查看简单迁移指南:https : //github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2