富贵资源网 Design By www.hznty.com

本文实例讲述了jquery分析文本里url或邮件地址为真实链接的方法。分享给大家供大家参考。具体如下:

这段代码可以分析出文本里的所有超级链接,包含邮件、url、#链接等等,并分别输出为真实链接地址

$.fn.tweetify = function() {
 this.each(function() {
  $(this).html(
   $(this).html()
    .replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)"$1">$1</a>')
    .replace(/(^|\s)#(\w+)/g,'$1<a href="http://search.twitter.com/search">#$2</a>')
    .replace(/(^|\s)@(\w+)/g,'$1<a href="http://twitter.com/$2">@$2</a>')
  );
 });
 return $(this);
}

用法:
复制代码 代码如下:$("p").tweetify();

原始文本:
复制代码 代码如下:<p>@seanhood have you seen this http://icanhascheezburger.com/ #lol</p>

分析以后:

<p><a href="http://twitter.com/seanhood">@seanhood</a> have you seen this
<a href="http://icanhascheezburger.com/">http://icanhascheezburger.com/</a>
<a href="http://search.twitter.com/search">#lol</a></p>

希望本文所述对大家的jQuery程序设计有所帮助。

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com