JS setInterval函数实现倒计时

2018-08-27 11:08:00 浏览数 (1)

代码语言:javascript复制
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()   "://"
			  request.getServerName()   ":"   request.getServerPort()
			  path   "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">


<title>操作成功</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

</head>

<body>
	<div id="content">
		<div id="infowrap">
			<div id="box">
				<h3>操作成功,3秒钟后自动跳转到首页</h3>


				<input type="text" value="3" id="time" class="fr">

			</div>
		</div>
	</div>
</body>
<script language="javascript">
	var t = 3;
	var time = document.getElementById("time");
	function fun() {
		t--;
		time.value = t;
		if (t <= 0) {
			location.href = "/sizheng/pages/back/admin_frame.jsp";
			clearInterval(inter);
		}
	}
	var inter = setInterval("fun()", 1000);
</script>
</html>

0 人点赞