zoukankan      html  css  js  c++  java
  • jsavascript 目录的操作(摘抄)

     取字符串的三个函数:slice(start,[end]),substring(start,[end])和substr(start,[length])

    常用的路径获取方式如下:

    http://localhost:8020/a/b/c.html
     

    window.location.pathname.substring(1, window.location.pathname.substring(1).indexOf('/')) :获取  a


    window.location.pathname:设置或获取对象指定的“文件名”或路径。/a/b/c.html

    window.location.href:设置或获取整个 URL 为字符串。http://localhost:8020/a/b/c.html

    window.location.port:设置或获取与 URL 关联的端口号码。8020

    window.location.protocol:设置或获取 URL 的协议部分。http:

    window.location.hash:设置或获取 href 属性中在井号“#”后面的分段。参数

    window.location.host:设置或获取 location 或 URL 的 hostname 和 port 号码。127.1.1.1:8020

    window.location.search:设置或获取 href 属性中跟在问号及其后面的部分(包含问号)。

      function getRootPath()   {     
                    var curPath = window.location.href;
                    //获取主机地址之后的目录,如: /a/b/c.html
                    var pathName = window.location.pathname;
                    //  a/b/c.html
                    var a = pathName.substring(1);
                    var b = a.indexOf('/');
                    //   a
                    var c = pathName.substring(1, b + 1);
                    var d = curPath.indexOf(pathName);
                    var pos = d + 1 + b;
                    //http://127.0.0.1:8020/a
                    var url = window.location.href.substring(0, pos);
                    return url;
                }

  • 相关阅读:
    [Python]打印Python的版本信息
    [Python]YIELD_2
    [Python]YIELD_1
    [Linux]查看Linux版本信息
    [Python]Python的class(类)中的object是什么意思
    [Linux]Linux里查看所有用户
    [Python]NEXT方法
    [Linux]主机配置互信
    [Linux]重启命令【echo "b" > /proc/sysrq-trigger】和【reboot】
    [Python]利用PDB来进行Python调试
  • 原文地址:https://www.cnblogs.com/ruiyuan/p/11245815.html
Copyright © 2011-2022 走看看