zoukankan      html  css  js  c++  java
  • JavaScript 27 Location

    Location表示浏览器中的地址栏

    示例 1 : 

    刷新当前页面

    <span>当前时间:</span>
    <script>
      var d = new Date();
      document.write(d.getHours());
      document.write(":");
      document.write(d.getMinutes());
      document.write(":");
      document.write(d.getSeconds());
      document.write(":");
      document.write(d.getMilliseconds());
     
    function refresh(){
      location.reload();
    }
    </script>
     
    <br>
    <button onclick="refresh()">刷新当前页面</button>

      示例 2 : 

    跳转到另一个页面

    <script>
    function jump(){
      //方法1
      //location="/";
     
      //方法2
      location.assign("/");
       
    }
    </script>
     
    <br>
    <button onclick="jump()">跳转到首页</button>

     示例 3 : 

    Location的其他属性

    <script>
    function p(s){
    document.write(s);
    document.write("<br>");
    }

    p("协议 location.protocol:"+location.protocol);
    p("主机名 location.hostname:"+location.hostname);
    p("端口号 (默认是80,没有即表示80端口)location.port:"+location.port);

    p("主机加端口号 location.host: "+location.host);
    p("访问的路径 location.pathname: "+location.pathname);

    p("锚点 location.hash: "+location.hash);
    p("参数列表 location.search: "+location.search);

    </script>

  • 相关阅读:
    UVA 10935 约瑟夫环
    分拆素数和 埃氏筛法
    POJ 2349 Prim
    POJ 2031 prim
    POJ 1861 Kruskal
    POJ 2395 Prim
    POJ 1751 Prim
    POJ 2421 Prim
    vuejs开发环境搭建及热更新
    vuejs介绍
  • 原文地址:https://www.cnblogs.com/JasperZhao/p/13370124.html
Copyright © 2011-2022 走看看