【发布时间】:2018-08-30 22:36:11
【问题描述】:
我每天都会将网页文件保存在公共驱动器上。然后我必须将 html 文件的直接链接发送给客户端。
为此,我倾向于手动将文件夹目录中的所有反斜杠“\”转换为正斜杠“/”,并在开头添加“http://”。
例子:
从
\\Public\Drive\PageLocation\
到http://Public/Drive/PageLocation/index.html
我已经开始使用查找和替换选项,但我觉得如果有某种代码可以在输入字段中转换这些路径会更好。
以下是我的想法的简要介绍:
*{font-family:sans-serif;}
p{
font-weight:bold;
}
<p>Folder Directory to URL </p>
<input type="text" placeholder="\\Public\Drive\PageLocation\">
<input type="submit" value="Convert">
<br>
<span>Result: http://Public/Drive/PageLocation/index.html</span>
<br/><br/>
<p>URL to Folder Directory </p>
<input type="text" placeholder="http://Public/Drive/PageLocation/index.html">
<input type="submit" value="Convert">
<br>
<span>Result: \\Public\Drive\PageLocation\</span>
我已经尝试弄清楚 JavaScript RegExp,但我没有找到太多的运气使它能够正常工作。似乎它只能读取双反斜杠并忽略单打:
var FolderDirectory = "\\Public\Drive\PageLocation";
var URLConvert = FolderDirectory.replace(/\\/g, "/");
alert(URLConvert);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
是否有转换斜线的热键之类的东西?
你们都用什么?
有没有其他方法可以在本地转换斜杠?
你会推荐什么?
谢谢。
【问题讨论】:
标签: javascript html directory directory-structure