Monthly Archives: May 2011

匹配一段文本中URL的正則問題

在項目中有個這樣的設計,備註中的URL自動識別為點擊的鏈接,對此的處理方式是用正則匹配出URL部分,然後替換成<a href=URL>URL這樣即可。其主要部分是正則匹配出URL部分。 假設有這麼一段文本。 你好,我是一段文本。我鏈接到http://leeiio.me/test.html請大家多多指教。 那麼我們可以這麼寫。 var text = "你好,我是一段文本。我鏈接到http://leeiio.me/test.html請大家多多指教。"; var regexp = /((http|ftp|https|file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\-\.\/?\@\%\!\&=\+\~\:\#\;\,]*)?)/ig; text = text.replace(regexp,"<a href=’$1′>$1</a>"); console.log(text);var text = "你好,我是一段文本。我鏈接到http://leeiio.me/test.html請大家多多指教。"; var regexp = /((http|ftp|https|file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\-\.\/?\@\%\!\&=\+\~\:\#\;\,]*)?)/ig; text = text.replace(regexp,"<a href=’$1′>$1</a>"); console.log(text); 但是如果URL中帶有中文,那麼以上的就不頂事了。

Posted in Skill | 技術 | 12 Comments

Link

The Difference Between jQuery』s .bind(), .live(), and .delegate()

西方不夠好的朋友可以看這篇譯文《jQuery的.bind()、.live()和.delegate()之間的區別》。這篇文章詳細的比較了bind(),live()以及delegate()的區別。以及作者為什麼推薦用delegate()。

Posted in Skill | 技術 | 3 Comments

Page 1 of 11