- $.fn.replaceUrl = function() {
- var regexp = /((ftp|http|https):\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-\\/]))?)/gi;
- return this.each(function() {
- $(this).html(
- $(this).html().replace(regexp,'<a href="$1">$1</a>')
- );
- });
- }
- //用法
- $('p').replaceUrl();
- //该片段来自于http://www.codesnippet.cn/detail/060120131345.html
来源: http://www.codesnippet.cn/detail/060120131345.html