這篇文章主要介紹了如何設置一定時間內只能發送一次請求,需要的朋友可以參考下
代碼如下: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>一定時間內,只能發送一次請求</title> <script type="text/javascript" src="${pageContext.request.contextPath}/editor/jquery/jquery-1.4.4.min.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <SCRIPT LANGUAGE="JavaScript"> var maxtime = 10;//設置至少10才能發送一次請求 function test(obj){ if(obj.value=='提交'){ check(); btn = setInterval("CountDown()",1000); }else{ alert("一分鐘內只能發送一次!"); } } function CountDown(){ if(maxtime>=0){ seconds = Math.floor(maxtime%60); msg = "距離時間結束還有"+seconds+"秒"; $("#btn").val(msg); --maxtime; }else{ $("#btn").val("提交"); clearInterval(btn); maxtime = 10; } } function check(){ alert("哈哈,到我了!"); } </SCRIPT> </head> <body> <input type="button" id="btn" value="提交" onclick="test(this)"/> </body> </html>