zoukankan      html  css  js  c++  java
  • js技巧专题篇: 页面跳转

    本篇主要介绍网页上常见的页面跳转技术。页面跳转有几种方式,比较常用的是window.location.href,window.location.replace,window.open,当然还有目前比较火的很多框架都采用的无刷新页面跳转技术window.history.pushState和window.history.replaceState。这些我都不讲^_^,我这里讲得是meta的一个相关配置。我相信,很多朋友看见实现的页面时会非常面熟,特别是男性!

    以下是相关代码实现:

     1 <!DOCTYPE html> 
     2 <html>
     3  <head lang="en"> 
     4 <meta charset="UTF-8"> 
     5 <meta http-equiv="refresh" content="5;url=https://www.baidu.com"/> 
     6 <title></title>
     7  <style> 
     8 span { 
     9 color: red;
    10  padding: 5px 15px;
    11  background: #cccccc; 
    12 } 
    13 button {
    14  padding: 10px;
    15  display: inline-block;
    16  vertical-align:top; 
    17 border-radius: 4px;
    18 outline: none; }
    19  </style> 
    20 </head>
    21  <body> 
    22 <h1>对不起您浏览的页面已改变,<span>5</span> 秒后自动为您跳转... <button>手动跳转</button>
    23 </h1>
    24  <script>
    25  var span = document.querySelector('span'),
    26  btn = document.querySelector('button'); 
    27 var selfTimer = (function(){ var i = 5;
    28  return function(){
    29  span.innerHTML = --i;
    30  if (i == 0) 
    31 { clearInterval(timer); 
    32 } } })()
    33  timer = setInterval(selfTimer, 1000); 
    34 btn.onclick = function() {
    35  window.location.hash = 'https://www.baidu.com'; } 
    36 </script> 
    37 </body>
    38  </html>

    最后感谢慕课网的:
     作者:外号理论汪 
    来源:慕课网

  • 相关阅读:
    ff与ie 的关于js兼容性
    CSS清除浮动的方法
    java8 LocalDateTime
    BigDecimal
    JAVA将 Word 文档转换为 PDF
    Ionic4
    SpringBoot后端统一格式返回
    SpringBoot集成JWT
    Java Lombok
    SpringBoot 中通过 CORS 解决跨域问题
  • 原文地址:https://www.cnblogs.com/jichuang/p/6777723.html
Copyright © 2011-2022 走看看