Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
function urllinks(str){ return str.replace(/\b((http|https):\/\/\S+)/g,'<a href="$1" target="_blank">$1</a>'); }
此代码仅替换“http”和“https”文本......但它不会替换以“www”开头的文本......
我没试过
function urllinks(str){ str = str.replace(/\b(www\.\S+)/g,'http://$1'); return str.replace(/\b((http|https):\/\/\S+)/g,'<a href="$1" target="_blank">$1</a>'); }