Javascript jQuery-从包含";的URL字符串获取绝对路径/&引用;
我不知道以前是否已经回答过了。我不知道该找什么 我想知道的是,对于以下问题是否有jquery函数 假设我有这样一个URL字符串-Javascript jQuery-从包含";的URL字符串获取绝对路径/&引用;,javascript,jquery,url,Javascript,Jquery,Url,我不知道以前是否已经回答过了。我不知道该找什么 我想知道的是,对于以下问题是否有jquery函数 假设我有这样一个URL字符串-www.example.com/a/b/./c 我想获得www.example.com/a/c一种简单的方法是创建一个link元素,设置其href属性,然后读取它 var a = document.createElement("a"); a.href = "http://www.example.com/a/b/../c"; var resolved = a.href;
www.example.com/a/b/./c
我想获得
www.example.com/a/c
一种简单的方法是创建一个link元素,设置其href
属性,然后读取它
var a = document.createElement("a");
a.href = "http://www.example.com/a/b/../c";
var resolved = a.href;
console.log(resolved); // "http://www.example.com/a/c"
或者使用一些jQuery:
var resolved = $("<a>").prop("href", "http://www.example.com/a/b/../c").prop("href");
console.log(resolved); // "http://www.example.com/a/c"
var已解析=$(“
这与当前文档的路径相关,尽管与上面的URL无关,因为URL是绝对的
请注意,这里使用的是反射属性,而不是属性,这一点很重要。一种简单的方法是创建链接元素,设置其href
属性,然后读取它
var a = document.createElement("a");
a.href = "http://www.example.com/a/b/../c";
var resolved = a.href;
console.log(resolved); // "http://www.example.com/a/c"
或者使用一些jQuery:
var resolved = $("<a>").prop("href", "http://www.example.com/a/b/../c").prop("href");
console.log(resolved); // "http://www.example.com/a/c"
var已解析=$(“
这与当前文档的路径相关,尽管与上面的URL无关,因为URL是绝对的
请注意,这里使用的是反射属性,而不是属性,这一点很重要。这真是太棒了!没想过!太棒了!非常感谢!@rmrinmoy::-)不用担心。如果这回答了您的问题,堆栈溢出的工作方式,您就“接受”点击旁边的复选标记来回答问题:但前提是它确实回答了问题。这真是太棒了!从没想过!太棒了!非常感谢!@rmrinmoy::-)不用担心。如果这回答了您的问题(堆栈溢出的工作方式),您可以通过单击旁边的复选标记来“接受”答案:但前提是它确实回答了问题。