![](/img/trans.png)
[英]javascript: if radio button is selected, on submit wait 2 seconds, then show alert
[英]When button is pressed wait 3 seconds then submit javascript
我如何制作一個 Javascript,當我按下提交按鈕時,它會將按鈕的名稱更改為“正在加載...”之類的內容,3 秒后應按下按鈕
<input type="Submit" name="submitNew" id="submitNew" value="Send">
它將充當人類的“垃圾郵件過濾器”。
一種可能的解決方案是通過以下方式為form
元素設置submit
事件:
HTML:
<form onsubmit="return formSubmit(this);">
JavaScript:
function formSubmit(form) {
document.getElementById("submitNew").value = "Loading...";
setTimeout(function() {
form.submit();
}, 3000); // 3 seconds
return false;
}
另一種方法是動態設置事件(向小貓致敬! ):
window.onload = function() {
document.getElementById("formID").onsubmit = function() {
var form = this;
document.getElementById("submitNew").value = "Loading...";
setTimeout(function() {
form.submit();
}, 3000); // 3 seconds
return false;
};
};
演示: http : //jsfiddle.net/spWDk/
您可以嘗試以下解決方案:
<form action="https://google.com" method="post" name="simulation" id="simulation">
<input type="text" name="nom" id="nom"/>
<input type="text" name="prenom" id="prenom"/>
<input type="submit" value"Submit">
</form>
<script>
$("#simulation").on('submit', function (e) {
console.log("Submitted");
//stop form submission
e.preventDefault();
//Do your custom work.
setTimeout(function(){ document.getElementById('simulation').submit(); }, 5000);
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.