0
有一個網站example.com。我想更改該網站上的所有鏈接,以便它們顯示在不同的主機上。我需要更改這些類型的鏈接:使用js/jquery更改頁面上所有鏈接的主機
<a href="page.html?attr=1">Link</a>
<a href="example.com/page2.html?attr=1">Link</a>
<a href="subdomain.example.com/page3.html?attr=1">Link</a>
到
<a href="mirror.com/page.html?attr=1">Link</a>
<a href="mirror.com/page2.html?attr=1">Link</a>
<a href="subdomain.mirror.com/page3.html?attr=1">Link</a>
而留下的形式和js網址爲是。我想知道做什麼是不痛苦的方式?我知道使用正則表達式解析URL是不好的,那麼我怎樣才能將這些URL作爲一個類來解析並對它們進行操作?