用JavaScript防止重復(fù)提交表單form的兩種方法。
1、用javascript設(shè)置一個(gè)變量,只允許提交一次。
<script type="text/javascript">
var checkSubmitFlg = false;
function checkSubmit(){
if (checkSubmitFlg == true){
return false;
}
checkSubmitFlg = true;
return true;
}
document.ondblclick =
function docondblclick(){
window.event.returnValue = false;
}
document.onclick =
function doconclick(){
if (checkSubmitFlg){
window.event.returnValue = false;
}
}
</script>
<form action="action.php" method="post" onsubmit="return checkSubmit();">
2、用javascript將提交按鈕或者img置為disable
<form action="action.php" method="post" onsubmit="getElById('submitInput').disabled = true;return true;">
<img styleId="submitInput" src="images/ok_b.gif" border="0" />
</form>
該文章在 2010/12/31 10:26:31 編輯過