zoukankan      html  css  js  c++  java
  • js获取项目根路径(应用路径方法)

    http://www.cnblogs.com/linjiqin/archive/2011/03/07/1974800.html
     
    //js获取项目根路径,如: http://localhost:8083/uimcardprj
    function getRootPath(){
    //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp
    var curWwwPath=window.document.location.href;
    //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp
    var pathName=window.document.location.pathname;
    var pos
    =curWwwPath.indexOf(pathName);
    //获取主机地址,如: http://localhost:8083
    var localhostPaht=curWwwPath.substring(0,pos);
    //获取带"/"的项目名,如:/uimcardprj
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    return(localhostPaht+projectName);
    }
     
    这是我在js中获得应用路径的方法
    var pathName=window.location.pathname;
    var projectName=pathName.substring(1, pathName.indexOf("/", 1));
     
    可以得到应用名:shopping
     

    indexOf()定义和用法

    indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。

    语法

    stringObject.indexOf(searchvalue,fromindex)
    参数描述
    searchvalue 必需。规定需检索的字符串值。
    fromindex 可选的整数参数。规定在字符串中开始检索的位置。它的合法取值是 0 到 stringObject.length - 1。如省略该参数,则将从字符串的首字符开始检索。
     
     
    substring(start,end)
    返回值

    一个新的字符串,该字符串值包含 stringObject 的一个子字符串,其内容是从 start 处到 stop-1 处的所有字符,其长度为 stop 减 start。

    说明

    substring 方法返回的子串包括 start 处的字符,但不包括 end 处的字符。(substring包头不包尾)
    I'm falling off the sky all alone.The courage inside is gonna break the fall. Nothing can dim my light within. I am That I am 程序 = 数据结构 + 算法
  • 相关阅读:
    【angularJS】启动(bootstrap)机制
    【angularJS】定义模块angular.module
    【angularJS】简介
    .NET AutoMapper学习记录
    WebAPI学习
    【MongoDB】在C#中使用
    RabbitMQ介绍及windows下安装使用
    【MongoDB】初识
    php命名空间(nameSpace)的使用详解
    魔术方法
  • 原文地址:https://www.cnblogs.com/IamThat/p/2892526.html
Copyright © 2011-2022 走看看