我需要自動鏈接頁面中的URL。使用jquery自動鏈接頁面中的網址
例如
這是一個HTML內容和包含文本URL www.example.com和鏈接的URL < A HREF = 'www.example.com' >例如< /一個>。它可能後跟HTTP像[http://www.example.com]
我需要的結果是這樣的:
這是HTML內容,幷包含文字網址http://www.example.com和鏈接的URL http://www.example.com。它可能跟着像http://www.example.com
我已經使用下面的功能,但它不與URL開始與www。
jQuery.fn.autolink = function() { return this.each(function() { //URLs starting with http://, https://, or ftp:// var re = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-\{\}$!|]+(?![\w\s?&.\/;#~%"=-]*>))/g; $J(this).html($J(this).html().replace(re, '$1 ')); }); }
你試過已經不錯了,或者你只是不知道如何下手? – 2013-04-10 07:38:29
@roXon是的。我用正則表達式來嘗試,但我無法得到正確的解決方案。我更新了我的問題與jquery函數 – Santhanakumar 2013-04-10 08:49:30