基于JS实现操作成功之后自动跳转页面

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

基于JS实现操作成功之后自动跳转页面

鱼还在鱼塘里   2020-09-25 我要评论

本文着重讲解了基于JS实现操作成功之后自动跳转页面的相关知识,文中会用代码示例为大家做详细介绍,希望能够帮助到您,欢迎大家阅读和收藏

如图所示样子:

在这里插入图片描述

制作一个跳转提示页面:
要求:
1. 如果打开该页面后,如果不做任何操作则5秒后自动跳转到一个新的地址,如百度主页。
2. 如果点击“返回”按钮则返回前一个页面

<!DOCTYPE html>
<html>
 <head>
 <title>浏览器对象</title> 
 <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>  
 </head>
 <body>
 <!--先编写好网页布局-->
 
 <div><h1>操作成功</h1></div>
 <div><a id ="p1">5</a>后回到主页<a href="http://www.baidu.com" rel="external nofollow" >返回</a></div>
 <script type="text/javascript"> 
 
  
  
  //获取显示秒数的元素,通过定时器来更改秒数。
   
   var num = 100;
   function downTime(){
		 document.getElementById('p1').innerHTML=num;
     if(num>0){
      num--;
     }else{
       window.location = "http://www.baidu.com";
     }
     setTimeout("downTime()",1000);
   }
  //通过window的location和history对象来控制网页的跳转。
  downTime();
 </script> 
</body>
</html>

PS:下面看下JavaScript五秒自动跳转到新页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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;
}
}
</script>
</head>

<body>
<span id="jumpTo">5</span>秒后自动跳转到//www.qb5200.com/
<script type="text/javascript">countDown(5,'//www.qb5200.com');</script>
</body>
</html>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们