jQuery文本链接脚本?

jQuery文本链接脚本?,第1张

jQuery文本链接脚本

对我来说,这似乎是jQuery的完美任务。

…这样的事情浮现在我脑海

// Define: linkify plugin(function($){  var url1 = /(^|&lt;|s)(www..+?..+?)(s|&gt;|$)/g,      url2 = /(^|&lt;|s)(((https?|ftp)://|mailto:).+?)(s|&gt;|$)/g,      linkifyThis = function () {        var childNodes = this.childNodes, i = childNodes.length;        while(i--)        {          var n = childNodes[i];          if (n.nodeType == 3) { var html = $.trim(n.nodevalue); if (html) {   html = html.replace(/&/g, '&amp;')   .replace(/</g, '&lt;')   .replace(/>/g, '&gt;')   .replace(url1, '<a href="http://"></a>')   .replace(url2, '<a href=""></a>');   $(n).after(html).remove(); }          }          else if (n.nodeType == 1  &&  !/^(a|button|textarea)$/i.test(n.tagName)) { linkifyThis.call(n);          }        }      };  $.fn.linkify = function () {    return this.each(linkifyThis);  };})(jQuery);// Usage example:jQuery('div.textbody').linkify();


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5017896.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存