< div id= "text" >
my Baidu
< / div >
< script type=" text/javascript ">
var txt = document.getElementById ("text"). InnerHTML;
var regexp = / (http://|https://)((w|=|?|.|/|&|-)+)/g; / / regular match
txt1=txt.replace (regexp,function ($url) {
return "<a href="" + $url + "" target="_blank">" + $url + "</a>";
});
document.getElementById ("text") .innerHTML = txt1
/ / alert (txt.replace (regexp, "m"));
/ / alert (txt);
< / script >