2

さまざまなhrefとのリンクがいくつかあり、次のようなこの値の明確なURLを取得したいと考えています。

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")$("a:first").attr("href")href 属性のテキストを提供するものとは対照的に、最初のアンカー タグの完全な URL を提供します。

于 2012-05-17T08:54:36.873 に答える