


jquery method to analyze the url or email address in the text as a real link_jquery
May 16, 2016 pm 03:53 PM本文实例讲述了jquery分析文本里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><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>
希望本文所述对大家的jQuery程序设计有所帮助。

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Outlook emails lost from control panel in Windows 11

How to download links starting with 115://? Download method introduction

How to get the WeChat video account link? How to add product links to WeChat video account?

What are the requirements for a video link? How to link the video account with goods?

Why NameResolutionError(self.host, self, e) from e and how to solve it

How to link on Doudian - Tutorial on linking on Doudian

How to use PUT request method in jQuery?

What is the difference between html and url
