zoukankan      html  css  js  c++  java
  • JavaScript获取路径

    JavaScript获取路径


    1、设计源代码

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        
        <title>JavaScript获取路径</title>
        
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<script type="text/javascript">
    	     function findPath()
    	     {
    	          //获取当前网址
    	          var curNetAddr = window.document.location.href;
    	          alert("获取当前网址:" + curNetAddr);
    	          
    	          //获取主机地址之后的文件夹
    	          var hostPath = window.document.location.pathname;
    	          alert("获取主机地址之后的文件夹:" + hostPath);
    	          
    	          //返回某个指定的字符串值在字符串中首次出现的位置
    	          var count = curNetAddr.indexOf(hostPath);
    	          alert("返回某个指定的字符串值在字符串中首次出现的位置:" + count);
    	          
    	          //获取主机地址
    	          var hostAddr = curNetAddr.substring(0,count);
    	          alert("获取主机地址:" + hostAddr);
    	          
    	          //获取带“/”的项目名
    	          var projectName = hostPath.substring(0,hostPath.substr(1).indexOf('/')+1);
    	          alert("获取带“/”的项目名:" + projectName);
    	          
    	          //获取项目路径
    	          var path = hostAddr + projectName;
    	          alert("获取项目路径:" + path);
    	     }
    	</script>
    
      </head>
      
      <body>
         <div id="body_div">
             <input type="button" id="btn" value="获取路径" onclick="findPath()"/>
         </div>
      </body>
    </html>
    

    2、设计结果

    (1)初始化时

             


    (2)获取当前网址

           


    (3)获取主机地址之后的文件夹

          


    (4)返回某个指定的字符串值在字符串中首次出现的位置

         


    (5)获取主机地址

         


    (6)获取带“/”的项目名

         


    (7)获取项目路径

         



  • 相关阅读:
    STM32 Timer : Base Timer, Input Capture, PWM, Output Compare
    Bus Blaster v4 design overview
    JTAG Communications model
    ARM JTAG 信号 RTCK 应该如何处理?
    HappyJTAG2
    用SWD调试接口测量代码运行时间 ( SWO )
    ARM Cortex Design Considerations for Debug
    Technical Information ARM-related JTAG / SWD / SWV / ETM Target Interfaces
    Keil debugging techniques and alternative printf (SWO function)
    Serial Wire Viewer (SWV)
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4607669.html
Copyright © 2011-2022 走看看