2

我有一些带有各种hrefs的链接,并希望获得此值的最终网址,例如:

http://localhost/   -> http://localhost/
localhost           -> http://mysite.example/localhost
firstpage           -> http://mysite.example/firstpage
/anotherpage        -> http://mysite.example/anotherpage
#anchor1            -> http://mysite.example/currentpage#anchor1
/#anchor2           -> http://mysite.example/#anchor2

顺便说一句,我不想​​要点击处理的代码。我能做到。

4

1 回答 1

5

$("a:first").prop("href")将为您提供第一个锚标记的完整 URL,而不是为$("a:first").attr("href")您提供 href 属性中的文本。

于 2012-05-17T08:54:36.873 回答