JavaScript中如何设置一个基础路径变量(basePath)呢?

2026-04-06 19:180阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计135个文字,预计阅读时间需要1分钟。

JavaScript中如何设置一个基础路径变量(basePath)呢?

主要用来替代jsp中经常使用的basePath+/**/来减少相对路径,而增加basePath*+*项目上下文访问路径+*/*。例如:/myproject/*。

JavaScript中如何设置一个基础路径变量(basePath)呢?

主要用来替代jsp中经常使用的basePath

/* * 减少相对路径而添加的basePath * 主要用来替代jsp中经常使用的basePath * */ /** * 项目上下文访问路径 * 如:/myproject * @type {string} */ var projectPath = window.location.pathname == 'null'?'':window.location.pathname.substring(0,window.location.pathname.indexOf('/',1)); /** * 服务器地址 如 : localhost:8080 * @type {string|Array|*|string|Array. } */ var serverPath = window.location.origin; /** * 便于服务器资源访问的basePath * 如:localhost:8080/myproject * @type {string} */ var basePath = serverPath + projectPath;

本文共计135个文字,预计阅读时间需要1分钟。

JavaScript中如何设置一个基础路径变量(basePath)呢?

主要用来替代jsp中经常使用的basePath+/**/来减少相对路径,而增加basePath*+*项目上下文访问路径+*/*。例如:/myproject/*。

JavaScript中如何设置一个基础路径变量(basePath)呢?

主要用来替代jsp中经常使用的basePath

/* * 减少相对路径而添加的basePath * 主要用来替代jsp中经常使用的basePath * */ /** * 项目上下文访问路径 * 如:/myproject * @type {string} */ var projectPath = window.location.pathname == 'null'?'':window.location.pathname.substring(0,window.location.pathname.indexOf('/',1)); /** * 服务器地址 如 : localhost:8080 * @type {string|Array|*|string|Array. } */ var serverPath = window.location.origin; /** * 便于服务器资源访问的basePath * 如:localhost:8080/myproject * @type {string} */ var basePath = serverPath + projectPath;