当前位置:Gxlcms > JavaScript > 怎样确认文本里url或邮件地址是否为真

怎样确认文本里url或邮件地址是否为真

时间:2021-07-01 10:21:17 帮助过:27人阅读

这次给大家带来怎样确认文本里url或邮件地址是否为真,确认文本里url或邮件地址为真的注意事项有哪些,下面就是实战案例,一起来看一下。

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

$.fn.tweetify = function() {
 this.each(function() {
  $(this).html(
   $(this).html()
    .replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1">$1</a>')
    .replace(/(^|\s)#(\w+)/g,'$1<a href="http://search.twitter.com/search?q=%23$2">#$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?q=%23lol">#lol</a></p>

相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

推荐阅读:

jquery操作动画显示与隐藏效果效果

jQuery选项卡切换特效实现步骤

以上就是怎样确认文本里url或邮件地址是否为真的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行