避免表单重复提交

来源:互联网 发布:淘宝网搜索 编辑:程序博客网 时间:2024/04/29 03:04

第一种:用flag标识,下面的代码设置checkSubmitFlg标志:

<script language=”javascript”>
           var checkSubmitFlg = false;

           function checkSubmit(){
                     if(checkSubmitFlg ==true){
return false;             //当表单被提交过一次后checkSubmitFlg将变为true,根据判断将无法进行提交。
}
                                     checkSubmitFlg ==true;
                                     return true;
}
< /script >
<form name=”form1” method=”post” onsubmit=”return checkSubmit();”>
           ………..
</form>


第二种:在onsubmit事件中设置,在第一次提交后使提交按钮失效,代码如下:

<form action=”about:blank” method=”post”
onsubmit =”getElementById(‘submitInput’).disabled=true; return true;”
target=”_blank”>
         <input type=”submit” id=”submitInput”/>

                   </form>

原创粉丝点击