带数字倒计时功能的 网页定时自动跳转
方法一
<!doctype html> <head> <meta charset=utf-8" /> <title>js定时跳转页面的方法</title> </head> <body> <script> var t=10;//设定跳转的时间 setInterval("refer()",1000); //启动1秒定时 function refer(){ if(t==0){ location="https://caovan.com"; //#设定跳转的链接地址 } document.getElementById('show').innerHTML=""+t+"秒后跳转到草凡博客"; // 显示倒计时 t--; // 计数器递减 //草凡博客转自: } </script> <span id="show"></span> </body> </html>
方法二
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <!-- 完成页面定时的跳转 --> <meta http-equiv="refresh" content="5;url=https://caovan.com"> <title>Insert title here</title> </head> <body onload="run()"> 页面将在<span id="spanId">5</span>秒后跳转!! </body> <br> <script type="text/javascript"> // 页面一加载完成,该方法就会执行 // 读秒,一秒钟数字改变一次 var x = 5; function run(){ // 获取到的是span标签的对象 var span = document.getElementById("spanId"); // 获取span标签中间的文本 span.innerHTML = x; x--; // 再让run方法执行呢,一秒钟执行一次 window.setTimeout("run()", 1000); } </script> </html>
方法三
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title></title> <script type="text/javascript"> function countDown(secs,surl){ var jumpTo = document.getElementById('jumpTo'); jumpTo.innerHTML=secs; if(--secs>0){ setTimeout("countDown("+secs+",'"+surl+"')",1000); } else{ location.href=surl; -ma } } </script> </head><br> <body> <h1>提交成功</h1> <a href=""><span id="jumpTo">3</span>秒后系统会自动跳转,也可点击本处直接跳</a> <script type="text/javascript"> countDown(3,'https://caovan.com'); </script> </body> </html>
参考原文:https://www.cnblogs.com/javahr/p/8410371.html
原创文章,作者:朋远方,如若转载,请注明出处:https://caovan.com/wangyedingshizidongtiaozhuan-deshixianfangfadaimadaquanjianyishoucang/.html