const convertToLink = (text) => {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var text1 = text.replace(exp, "<a href='$1'>$1</a>");
var exp2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
return text1.replace(exp2, '$1<a href="http://$2">$2</a>');
}发布于 2022-02-23 04:53:45
不能在textarea内呈现HTML。使用<p>代替
<p dangerouslySetInnerHTML={{ __html: convertToLink(text) }}></p>https://stackoverflow.com/questions/71231392
复制相似问题