复制代码 代码如下:
<%@ 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="https://www.jb51.net/${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" value="提交"/>
</body>
</html>