简体   繁体   English

将绝对路径转换为相对路径

[英]Converting absolute path to relative

What is best way to convert absolute path to relative path by javascript or jquery ? 通过javascript或jquery将绝对路径转换为相对路径的最佳方法是什么?

for example consider as below : 例如,考虑如下:

"http://localhost:2011/Content/Images/Product/Large/3.jpg" 

to

 "/Content/Images/Product/Large/3.jpg" 

Use the trick that <a> elements contain location properties. 使用<a>元素包含位置属性的技巧。

$("<a href='http://localhost:2011/Content/Images/Product/Large/3.jpg'>")
  .prop("pathname");

只需使用window.location.pathname

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM