js 怎样防止 刷新重复提交
展开全部
第一种方法:
<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>
<script Language='JavaScript'>
function formsubmit() {
Today = new Date();
var NowHour = Today.getHours();
var NowMinute = Today.getMinutes();
var NowSecond = Today.getSeconds();
var mysec = (NowHour*3600)+(NowMinute*60)+NowSecond;
if((mysec-document.formsubmitf.mypretime.value)>600)
//600只是一个时间值,就是5分钟内禁止重复提交,值随你高兴设
{
document.formsubmitf.mypretime.value=mysec;
}
else
{
alert(' 按一次就够了,请勿重复提交!请耐心等待!谢谢合作!');
return false;
}
document.forms.formsubmitf.submit();
}
</script>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<form name=formsubmitf id ="the" method="post" action="XXX.asp">
<input type=hidden name='mypretime' value='0'> //这句不能少,用隐含变量传递一个时间初值
//这里是你要提交的内容
<input type="button" value="写好了" name="button1" class="4round" onclick='formsubmit()'> <font class="red">(请按一次,耐心等待!)</font> <input type="reset" value="重 写" name="button2" class="4round">
</form>
望采纳!
<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>
<script Language='JavaScript'>
function formsubmit() {
Today = new Date();
var NowHour = Today.getHours();
var NowMinute = Today.getMinutes();
var NowSecond = Today.getSeconds();
var mysec = (NowHour*3600)+(NowMinute*60)+NowSecond;
if((mysec-document.formsubmitf.mypretime.value)>600)
//600只是一个时间值,就是5分钟内禁止重复提交,值随你高兴设
{
document.formsubmitf.mypretime.value=mysec;
}
else
{
alert(' 按一次就够了,请勿重复提交!请耐心等待!谢谢合作!');
return false;
}
document.forms.formsubmitf.submit();
}
</script>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<form name=formsubmitf id ="the" method="post" action="XXX.asp">
<input type=hidden name='mypretime' value='0'> //这句不能少,用隐含变量传递一个时间初值
//这里是你要提交的内容
<input type="button" value="写好了" name="button1" class="4round" onclick='formsubmit()'> <font class="red">(请按一次,耐心等待!)</font> <input type="reset" value="重 写" name="button2" class="4round">
</form>
望采纳!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询