我有一堆需要更換HREF鏈接:使用jQuery替換HREF,正則表達式
<a id="link" href="http://localhost:8091/tabid/99/catid/8/page1.aspx">Page1</a>
<a id="link" href="http://localhost:8091/tabid/98/catid/8/page1.aspx">Page1</a>
<a id="link" href="http://localhost:8091/tabid/97/catid/8/page1.aspx">Page1</a>
的HREF應改爲: 的「http://本地主機:8091/tabid/1個 /catid/8/page1.aspx」
通過搜索,我發現:
$(document).ready(function() {
$("#link").each(function() {
this.href = this.href.replace("99", "1");
});
});
這應該做的工作。但是,它只取代其中一個鏈接。任何人都可以幫助我在這裏的正則表達式?我需要將tabid/**/catid
中的所有數字更改爲「」。
你有多個元素具有相同的ID ...這是無效的。改變你的ID到類 –