我想知道如何在我的情况下使用这个脚本>>> https://stackoverflow.com/a/3890175/1503192 ...
这是我的 jsfiddle >>> jsfiddle.net/kZfGV/134/
HTML:
<body onLoad="linkify(inputText)">
https://google.com/<br />
http://google.com/<br />
https://www.google.com/<br />
http://www.google.com/<br />
www.google.com<br />
www.google.com<br />
admin@google.com
</body>
JS:
function linkify(inputText) {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with http://, https://, or ftp://
replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');
//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');
//Change email addresses to mailto:: links.
replacePattern3 = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');
return replacedText;
}
我已经在 jsfiddle 中尝试过,但在我的博客中尝试了这么多次之前我仍然无法弄清楚。我也在stackoverflow和google上搜索过这个,但似乎没有任何效果。我是这个领域的新手。请帮帮我。谢谢