50个比较实用jQuery代码段

2020-05-19 07:42:20易采站长站整理


$.fn.replaceUrl = function() {
var regexp = /((ftp|http|https)://(w+:{0,1}w*@)?(S+)(:[0-9]+)?(/|/([w#!:.?+=&%@!-/]))?)/gi;
this.each(function() {
$(this).html(
$(this).html().replace(regexp,'<a href="$1">$1</a>‘)
);
});
return $(this);
}
//用法 
$('p').replaceUrl();

就整理这么多吧。

如果大家看的还不过瘾,建议大家看下  超实用的jquery代码段一书。软件开发网正好有pdf版本。大家可以看下。