如何使用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的
中答案 0 :(得分:4)
var string = "This is going #right on the way";
string.replace(/#(\S*)/g,'<a href="http://twitter.com/#!/search/$1">$1</a>')
答案 1 :(得分:1)
这是我的建议
(function(){
$.fn.hashlink = function(){
this.text(this.text().replace(\#(w+)\),"<a href='twitter.com/#!/search/$1'>$1</a>")
text = \#w+\g.
}
})