N秒后跳转页面

xiaoxiao2021-02-27  353

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% 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>My JSP 'test.jsp' starting page</title> <script type="text/javascript" src="js/jquery.js"></script> <style type="text/css"> .popDiv{ position: fixed; margin:50px auto; font-size: 48px; display:none; color:purple; } </style> <script type="text/javascript"> //设定倒数秒数 var t = 5; //显示倒数秒数 function showTime(){ var str = "页面在【"+t+"】秒后跳转"; t -= 1; document.getElementById('div1').innerHTML= str; if(t==-1){ str = "跳转中..."; document.getElementById('div1').innerHTML= str; window.location = "http://www.baidu.com"; return; } //每秒执行一次,showTime() setTimeout("showTime()",1000); } function openWin(){ document.getElementById( 'div1' ).style.display = 'block'; showTime(); } </script> </head> <body> <div class="popDiv" id="div1"></div> <input type="button" value="开始计时" onclick="openWin()"/> </body> </html>
转载请注明原文地址: https://www.6miu.com/read-4119.html

最新回复(0)