由于您使用的是自定义HTML输入,因此库API中的常规设置不足以实现您的目标。我建议你使用
preConfirm
从其API函数中获取输入值,如下所示:
function addUser() {
swal({
html: `...`,
confirmButtonText: 'Confirm',
// ...
showCancelButton: true,
preConfirm: function() {
return new Promise((resolve, reject) => {
// get your inputs using their placeholder or maybe add IDs to them
resolve({
Email: $('input[placeholder="Email"]').val(),
Name: $('input[placeholder="Name"]').val(),
Password: $('input[placeholder="Password"]').val(),
Level: $('input[placeholder="Level"]').val()
});
// maybe also reject() on some condition
});
}
}).then((data) => {
// your input data object will be usable from here
console.log(data);
});
}