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&l开发者_StackOverflow中文版t;/a> on the way
The page lots's of # (hash) tag in different classes and id's
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/
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.
}
})
精彩评论