Jquery analyzes the url or email address in the text as a real link
This document describes how to analyze the url or email address in jquery text as a real link. Share it with you for your reference. The details are as follows:
This code can analyze all hyperlinks in the text, including emails, URLs, and # links, and output them as real link addresses respectively.
?
1 2 3 4 5 6 7 8 9 10 11 |
$. Fn. tweeiterator = function (){ This. each (function (){ Certificate (this).html ( Certificate (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 ); } |
Usage:
The Code is as follows:
$ ("P"). tweeiterator ();
Original text:
The Code is as follows:
@ Seanhood have you seen this http://icanhascheezburger.com/# lol
After analysis:
?
1 2 3 |
<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> |
I hope this article will help you with jQuery programming.