每天一個JavaScript執行個體-防止重複表格單提交,javascript執行個體

來源:互聯網
上載者:User

每天一個JavaScript執行個體-防止重複表格單提交,javascript執行個體

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>每天一個JavaScript執行個體-防止重複表格單提交</title><style>#refresh{display: none;width:200px;height:20px;background-color: #ff0;}</style><script>var inprocess = false;window.onload = function(){document.forms["picker"].onsubmit = validateSubmit;document.getElementById("refresh").onclick = startOver;}function validateSubmit () {// 防止重複的表單提交if (inprocess) return;inprocess = true;console.log(inprocess);document.getElementById("submitbutton").disabled = true;document.getElementById("refresh").style.display = "block";document.getElementById("message").innerHTML = "<p>正在processing,稍等</p>";return false;}function startOver(){inprocess = false;document.getElementById("submitbutton").disabled = false;document.getElementById("message").innerHTML = "";document.getElementById("refresh").style.display = "none";}</script></head><body><form id="picker" method="post" action="">group1:<input type="radio" name="group1" value="one" />group2:<input type="radio" name="group1" value="two" />group3:<input type="radio" name="group1" value="three" /><br /><br />Input 1: <input type="text" id="intext" />Input 2: <input type="text" id="intext2" />Input 3: <input type="text" id="intext3" /><input type="submit" id="submitbutton" value="send form" /></form><div id="refresh"><p>單擊我</p></div><div id="message"></div></body></html>


怎用javascript防止表單重複提交

<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>
 
怎可以有效地防止重複提交表單?

表單檔案formtest.asp

  <%
  Randomize '初始代隨機數種子
  num1=rnd() '產生隨機數num1
  num1=int(26*num1)+65 '修改num1的範圍以使其是A-Z範圍的Ascii碼,以防表單名出錯
  session("antry")="test"&chr(num1) '產生隨機字串
  %>

  <form name="test" action="testact.asp" method="post">
  你的名字:<input type='text' name='' size=30>  '注意本行中使用了隨機表單項名
  <input type='submit' value='提交'>
  </form>

  表單處理程式testact.asp

  <%
  teststr=request.form(session("antry"))
  if teststr="" then
   response.write "沒有填寫姓名或重複提交"
   '由於使用者沒有填寫名字,或表單被重複提交(標誌為session("antry")為空白)引起
  else
   response.write teststr
   session("antry")=""  '提交成功,清空session("antry"),以防重複提交!!
  end if
  %>

  在這裡,你只需隨機化一個必填項目的表單項名即可,不必隨機化所有的表單項目
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.