WEB前端

js防止短时间内重复提交表单数据

位置:首页 > WEB前端 > js教程,2013-08-16
js防止短时间内重复提交表单数据的代码如下<html><head><scriptLanguage='JavaScript'>functionformsubmit()...

js防止短时间内重复提交表单数据的代码如下

<html><head>
<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是一个时间值
    document.formsubmitf.mypretime.value=mysec;
} else {
  alert(' 请勿重复提交!请耐心等待!谢谢合作!');
  return false; }
document.forms.formsubmitf.submit();
}
</script>
</head>
<body>
<BODY BGCOLOR="#FFFFFF">
<center><font color=red size=5>javascript防止表单重复提交</font></center>
<form name=formsubmitf id ="the" method="post" action="http://www.ablanxue.com">
<input type=hidden name='mypretime' value='0'>
<table width="459" height="266" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
     <td bgcolor="F7FCFE"><div align="left"></div></td>
    <td bgcolor="F7FCFE" class="s">&nbsp;</td>
    <td height="18" bgcolor="F7FCFE"><div align="center"> </div></td>
    <td bgcolor="F7FCFE">&nbsp;</td>
    <td height="18" bgcolor="F7FCFE">&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="F7FCFE">&nbsp;</td>
    <td bgcolor="F7FCFE" class="s">用户名:<font color="#FF0000" >*</font></td>
    <td height="18" bgcolor="F7FCFE"><div align="center">
        <input name="user_nickname" type="text" size="20">
      </div></td>
    <td bgcolor="F7FCFE" class="s">&nbsp;</td>
    <td height="18" bgcolor="F7FCFE">&nbsp;</td>
  </tr>
  <tr>
    <td width="80" height="18" bgcolor="F7FCFE">&nbsp;</td>
    <td width="90" height="18" bgcolor="F7FCFE" class="s"><div align="left">密
        码:&nbsp;<font color="#FF0000" >*</font></div></td>
    <td width="180" height="18" bgcolor="F7FCFE"><div align="center">
        <input name="user_psw" type="password" size="20">
      </div></td>
    <td width="100" height="18" bgcolor="F7FCFE" class="s">(不能少于4位)</td>
    <td bgcolor="F7FCFE">&nbsp;</td>
  </tr>
  <tr>
    <td height="18" bgcolor="F7FCFE">&nbsp;</td>
    <td height="18" bgcolor="F7FCFE" class="s">重填密码:<font color="#FF0000" >*</font>
    </td>
    <td height="18" bgcolor="F7FCFE"><div align="center">
        <input name="user_psw1" type="password" size="20">
      </div></td>
    <td height="18" bgcolor="F7FCFE">&nbsp;</td>
    <td bgcolor="F7FCFE">&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="F7FCFE">&nbsp;</td>
    <td bgcolor="F7FCFE" class="s">电话:</td>
    <td height="18" bgcolor="F7FCFE"><div align="center">
        <input name="user_phone" type="text" size="20">
      </div></td>
    <td bgcolor="F7FCFE">&nbsp;</td>
    <td bgcolor="F7FCFE">&nbsp;</td>
  </tr>
</table>  
<center>        
<input type="button" value="写好了" name="button1" class="4round" onclick='formsubmit()'>
&nbsp;<font class="red">(请按一次,耐心等待!)</font>&nbsp;
<input type="reset" value="重 写" name="button2" class="4round">
</center>
</form>
</body>
</html> 
 

TAGS:js防止重复提交表单

猜你喜欢

NewHot