如何从 a.href 属性 在 Chrome 的 JavaScript 中获取相对路径?
How to get the relative path from a a.href property in Chrome's JavaScript?
如果在HTML的HTML页面中指定了<a href="{relative path}">...</a>
,Chrome的JavaScriptreturns中的a.href
属性当前 document.URL
.
的绝对路径
我知道我可以通过 replace()
、substr()
、indexOf()
的组合从那里提取相对路径部分,但我想避免这种情况。 property/function returns 是否正是 HTML 页面开发人员定义为 {relative path}
的 property/function?
getAttribute("href")
console.log(document.getElementById("a").getAttribute("href"))
<a id="a" href="/pages/index.html">Link</a>
如果在HTML的HTML页面中指定了<a href="{relative path}">...</a>
,Chrome的JavaScriptreturns中的a.href
属性当前 document.URL
.
我知道我可以通过 replace()
、substr()
、indexOf()
的组合从那里提取相对路径部分,但我想避免这种情况。 property/function returns 是否正是 HTML 页面开发人员定义为 {relative path}
的 property/function?
getAttribute("href")
console.log(document.getElementById("a").getAttribute("href"))
<a id="a" href="/pages/index.html">Link</a>