如何确定JavaScript中的OS路径分隔符?
时间:2020-03-06 14:38:49 来源:igfitidea点击:
如何在JavaScript中告诉运行脚本的OS中使用了什么路径分隔符?
解决方案
据我所知,只需使用" /",它就可以在所有操作系统上使用。
实际上,即使在Windows上,我们也始终可以将/用作路径分隔符。
引用http://bytes.com/forum/thread23123.html:
So, the situation can be summed up rather simply: All DOS services since DOS 2.0 and all Windows APIs accept either forward slash or backslash. Always have. None of the standard command shells (CMD or COMMAND) will accept forward slashes. Even the "cd ./tmp" example given in a previous post fails.
VVS的答案是正确的,除了解析Internet Explorer中文件输入所给出的路径(使用IE8测试,我不知道其他版本)。在这种情况下,输入元素的值(input.value)给出的路径的格式为" C:\ fakepath \ <文件名>"。注意这里的反斜杠。