开发者

please help me replace string pattern with jquery

开发者 https://www.devze.com 2022-12-13 03:52 出处:网络
using a twitter display widget and need to add links to the hash tags. so i need a pattern replacement, replacing each string that starts with a hash/pound sign and ends in a space with the twitter se

using a twitter display widget and need to add links to the hash tags. so i need a pattern replacement, replacing each string that starts with a hash/pound sign and ends in a space with the twitter search link. i am pretty clumsy w/jquery--can someone point me in the right direction -- thanks, anyone!

something taking me:

// FROM:
<ul id="tweets">
     <li>Some nutty tweet. #nutty</li>
     <li>A fruity tweet here. #fruity</li>
</ul>

// TO:
<ul id="tweets">
     <开发者_如何学运维;li>Some nutty tweet. <a href="http://twitter.com/search?q=%23nutty">#nutty</a></li>
     <li>A fruity tweet here. http://twitter.com/search?q=%23fruity">#fruity</a></li>
</ul>


Since you are using jQuery, I would recommend the jQuery Tweetify Text from the CSS-Snippets library.

You would then use it like this (given your code):

$("#tweets li").tweetify();

In addition to matching #hashes, it also turns URL's into hyperlinks, and matches @username and links to their profile.

0

精彩评论

暂无评论...
验证码 换一张
取 消