我正在尝试在Javascript中获取文件的当前目录,这样我就可以使用它来为我站点的每个部分触发不同的jquery函数。
if (current_directory) = "example" {
var activeicon = ".icon_one span";
};
elseif (current_directory) = "example2" {
var activeicon = ".icon_two span";
};
else {
var activeicon = ".icon_default span";
};
$(activeicon).show();
...
有什么想法吗?
发布于 2010-07-01 00:49:23
window.location.pathname将为您提供目录以及页面名称。然后,您可以使用.substring()来获取目录:
var loc = window.location.pathname;
var dir = loc.substring(0, loc.lastIndexOf('/'));
希望这能有所帮助!
发布于 2018-03-12 06:58:34
在Node.js中,您可以使用:
console.log('Current directory: ' + process.cwd());
发布于 2010-07-01 00:48:02
您可以使用window.location.pathname.split('/');
这将产生一个数组,其中包含/之间的所有项
https://stackoverflow.com/questions/3151436
复制相似问题