开发者

Change #hash tag to link on page load

开发者 https://www.devze.com 2023-04-09 08:43 出处:网络
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

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.
}    

})
0

精彩评论

暂无评论...
验证码 换一张
取 消