我使用Sweetalert2来确认和更新一些数据。 sweetalert的风格与bootstrap v4(alpha)相结合。 使用HTML生成多表单输入,如此示例。 获取输入数据后,会进行ajax调用以更新它。以下是我的例子:
swal({
title: 'Submit to confirm',
html:
'<input id="swal-input1" placeholder="input1" class="form-control mb-1">' +
'<input id="swal-input2" placeholder="input2" class="form-control">',
showCancelButton: true,
confirmButtonText: 'Submit',
showLoaderOnConfirm: true,
buttonsStyling: false,
confirmButtonClass: 'btn btn-primary btn-lg',
cancelButtonClass: 'btn btn-lg',
preConfirm: function () {
return new Promise(function (resolve) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val()
])
})
},
allowOutsideClick: false
}).then(function(email) {
$.ajax({
// ajax for post / get here to update current data with data from the input
});
}).catch(swal.noop)
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/sweetalert2/6.4.1/sweetalert2.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/sweetalert2/6.4.1/sweetalert2.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
&#13;
如何对自定义数据应用验证(空表单),然后进行ajax调用?