2
我在留言板上有一個大塊或文本,其中包含以#開頭的字符串。我可以使用jquery替換這些包含字符串的鏈接嗎?jquery替換所有以#開頭的字符串並添加鏈接
例如,更改:
<div id="mydiv">This is my #block of text with #multiple hash strings</div>
到:
<div id="mydiv">This is my <a href="newpage.asp?block">#block</a> of text with <a href="newpage.asp?multiple">#multiple</a> hash strings</div>
提前感謝!
歡迎的StackOverflow!在發佈之前測試你的解決方案總是一個好主意,可能在http://jsfiddle.net上,以確保它們實際上按預期工作。 – Blazemonger
使用'text()'和'html()'替換內容時應該是後果。如果html包含'>腳本<',替換後的結果將爲'