问题
How to change # tag + Character to link using javascript
This is going #right on the way
with
This is going <a href="http://twitter.com/#!/search/right">right</a> on the way
even this is also acceptable
This is going <a href="http://twitter.com/#!/search/right">#right</a> on the way
The page lots's of # (hash) tag in different classes and id's
回答1:
var string = "This is going #right on the way";
string.replace(/#(\S*)/g,'<a href="http://twitter.com/#!/search/$1">$1</a>')
Demo: http://jsfiddle.net/dKm82/
回答2:
here is my suggestion
(function(){
$.fn.hashlink = function(){
this.text(this.text().replace(\#(w+)\),"<a href='twitter.com/#!/search/$1'>$1</a>")
text = \#w+\g.
}
})
来源:https://stackoverflow.com/questions/7575041/change-hash-tag-to-link-on-page-load