将绝对路径转换为相对路径
问题描述:
通过javascript或jquery将绝对路径转换为相对路径的最佳方式是什么?将绝对路径转换为相对路径
例如考虑如下:
"http://localhost:2011/Content/Images/Product/Large/3.jpg"
到
"/Content/Images/Product/Large/3.jpg"
答
使用技巧,<a>
元素包含位置属性。
$("<a href='http://localhost:2011/Content/Images/Product/Large/3.jpg'>")
.prop("pathname");
绝妙的诀窍!你可以参考任何解释'pathname'道具的文档吗?我们可以依赖的其他道具是什么? – abernier
@abernier:[这是一个列表。](https://developer.mozilla.org/en/DOM/HTMLAnchorElement#Properties)虽然它确实说明它是HTML5。我不知道跨浏览器支持。 – pimvdb