<div class="codetitle"> <span><a style="CURSOR: pointer" data="402" class="copybut" id="copybut402" onclick="doCopy('code402')"><u>複製程式碼</u></a></span> 程式碼如下:</div> <div class="codebody" id="code402"> <br>pageEncoding="UTF-8"%> <br> <br> <br> <br> <br><title>在一段時間內,只能發送一次請求</title> <br><script type="text/javascript" src="%24%7BpageContext.request.contextPath%7D/%20editor/jquery/jquery-1.4.4.min.js"></script> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br><script language="JavaScript"> <BR>var maxtime = 10;//設定至少10才能發送一次請求<BR>function test(obj){ <BR>if(obj.value=='提交'){ <BR>check(); <BR>btn = setInterval("CountDown()",1000); <BR>}else{ <BR>alert("一分鐘內只能寄一次!"); <BR>} <BR>} <BR>function CountDown(){ <BR>if(maxtime>=0){ <BR>seconds = Math.floor(maxtime`); <BR>msg = "距離時間結束還有" seconds "秒"; <BR>$("#btn").val(msg); <BR>--maxtime; <BR>}else{ <BR>$("#btn").val("提交"); <BR>clearInterval(btn); <BR>maxtime = 10; <BR>} <BR>} <BR>function check(){ <BR>alert("哈哈,到我了! "); <BR>} <br><br></script> <br> <br> <br><input type="button" id="btn" value="提交" onclick="test(this)"> <br> <br> <br> </div>