// js 获取项目地址
var protocol = location.protocol;
var hostname = location.hostname;
var port = location.port; var pathname = location.pathname;
var basePath = protocol + "//" + hostname + ":" + port + pathname;
--------------------------------------------
// 如果项目地址结尾有 index.jsp,去掉 index.jsp
if ( basePath.indexOf( 'index.jsp' ) != -1 ) {
basePath = basePath.substr( 0, basePath.indexOf( 'index.jsp' ) );
}
---------------------------------------------
js 有 indexOf 函数,却没有 java 里那种 startsWith,endsWith 函数。
另外据说 js 中 startsWith,endsWith 函数不能在任何浏览器兼容
本文介绍了一种使用JavaScript来获取当前项目路径的方法,并演示了如何去除路径中的特定字符串(如'index.jsp')。此外,还讨论了JavaScript中缺乏类似于Java的startsWith和endsWith方法的问题。
665

被折叠的 条评论
为什么被折叠?



