[javascript][jquery]避免使用者連續按下兩次按鈕、送出、submit
參考以下javascript程式碼+html即可:
方法一:input type button
javascript:
$(document).ready(function () {
$('#btnSupplierSubmit').on('click', function (e) {
var confirmResult = confirm('確定送出?');
if (confirmResult) {
$('#formSupplierEdit').submit();
}
else {
e.preventDefault();
return false;
}
});
});
html:
<input type="button" id="btnSupplierSubmit" class="btn btn-primary m-2" value="SAVE" />
<form id="formSupplierEdit" method="post" enctype="multipart/form-data"></form>
補充方法二:input type submit
javascript:
function SelectedFormSubmit(e) {
e.preventDefault();
$('#btnCompleteSubmit').prop('disabled', true);
return false;
}
html:
<button type="submit" class="btn btn-primary" id="btnCompleteSubmit" >確定</button>
<form id="myForm" method="post" onsubmit="return SelectedFormSubmit(event)"></form>
參考資料:
工作經驗