Skip to content

Instantly share code, notes, and snippets.

@zzjin
Created October 23, 2013 10:51
Show Gist options
  • Save zzjin/7116504 to your computer and use it in GitHub Desktop.
Save zzjin/7116504 to your computer and use it in GitHub Desktop.
自动链接html中出现的url等
!function(a){a.fn.extend({linkUrl:function(){var b=/((?:https?|mailto):\/\/(?:www\.)?(?:[a-zA-Z0-9][a-zA-Z0-9\-]*\.)?[a-zA-Z0-9][a-zA-Z0-9\-]*(?:\.[a-zA-Z]+)+(?:\:[0-9]*)?(?:\/.[^\u4e00-\u9fa5\s<'"·×—‘’“”…、。《》『』【】!(),:;?]*)?)/gi;a(this).contents().each(function(){var e,c=a(this),d=c.clone();d.find("a").remove(),e=d.text().match(b),"undefined"!=typeof e&&null!=e&&("undefined"==typeof c.html()&&(c=c.wrap("<span />").parent()),a.each(e,function(b,d){var e=c.html().replace(a("<div />").text(d).html(),'<a href="'+d+'" target="_blank">'+d+"</a>");c.html(e)}))})}})}(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment