我需要自动链接页面中的 URL。
例如
这是一个 html 内容,包含文本 url www.example.com 和链接的 url <a href='www.example.com'> example </a>。后面可能是 http,例如 [http://www.example.com]
我需要结果是这样的:
这是一个 html 内容,包含文本 url http://www.example.com和链接的 url http://www.example.com。后面可能是 http,例如http://www.example.com
我使用了以下函数,但它不适用于以 www 开头的 url。
jQuery.fn.autolink = 函数() { 返回 this.each(function() { //以 http://、https:// 或 ftp:// 开头的 URL var re = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-\{\}$!|]+(?![\w\s? &.\/;#~%"=-]*>))/g; $J(this).html($J(this).html().replace(re, '$1')); }); }