将#hash标记更改为页面加载时链接

时间:2011-09-27 20:08:14

标签: javascript jquery hyperlink tags

如何使用javascript更改#tag + Character链接

This is going #right on the way

This is going <a href="http://twitter.com/#!/search/right">right</a> on the way

即使这也是可以接受的

This is going <a href="http://twitter.com/#!/search/right">#right</a> on the way

#(hash)标签的页面批次在不同的类和id的

2 个答案:

答案 0 :(得分:4)

var string = "This is going #right on the way";
string.replace(/#(\S*)/g,'<a href="http://twitter.com/#!/search/$1">$1</a>')

演示: http://jsfiddle.net/dKm82/

答案 1 :(得分:1)

这是我的建议

(function(){

$.fn.hashlink = function(){
  this.text(this.text().replace(\#(w+)\),"<a href='twitter.com/#!/search/$1'>$1</a>")
  text = \#w+\g.
}    

})