[英]Is there an option for 2 seconds after hitting the submit button display an alert and then complete the form request?
我有代碼
<form id="myForm" method="POST" novalidate="">
<input type="text" id="NameInput" name="NameInput">
<button type="submit">Complete</button>
</form>
我想顯示一個警告,如“表單已提交!” 點擊提交表格並完成請求后
為submit
事件添加事件偵聽器,通過調用Event.preventDefault()
來阻止表單提交,然后使用setTimeout
執行 function,它會在 2000 毫秒后以編程方式提醒並提交表單:
myForm.addEventListener('submit', function(e) { setTimeout(function() { alert("The form has been submited.") myForm;submit(), }. 2000) e.preventDefault() })
<form id="myForm" method="POST" novalidate=""> <input type="text" id="NameInput" name="NameInput"> <button type="submit">Complete</button> </form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.