【问题标题】:Help Parsing Twitter JSON Request using JQuery to appropriately style mentions and hashtags?帮助使用 JQuery 解析 Twitter JSON 请求以适当地设置提及和主题标签的样式?
【发布时间】:2011-11-18 14:41:43
【问题描述】:

我真的很想在这方面得到一些帮助。

我有一个 twitter JSON 请求,一切正常,但我想适当地设置提及和主题标签的样式,因为目前整条推文看起来都一样,我认为进行此更改会大大改善它。

目前我尝试更改主题标签,但似乎导致错误,我认为这是因为我正在使用$(this).html(linkHashtags($(this).html()));,而我正在阅读的不是html。

下一个阶段就是对@(提及)做同样的事情。

这是目前的代码:

var url='http://search.twitter.com/search.json?q=';
var query='%23HASHTAG';
var options='&result_type=recent&rpp=4&page=1&callback=?';
var html='<marquee behavior="scroll" scrollamount="1" direction="left">';

$.getJSON(url+query+options,function(json){     
        $.each(json.results,function(i,tweet){

             $(this).html(linkHashtags($(this).html()));

             html+='<span class="tweet"><img class="profile-pic" src="'+tweet.profile_image_url+'" width="40" height="40" /><span class="tweeter">'+tweet.from_user+'</span>:&nbsp;'+tweet.text+ ' <i>' + daysAgo(tweet.created_at) + '</i></span>';
        });

        html += '</marquee>';
       // Now replace the <p> with our <marquee>-element
       $('.twitter p').replaceWith(html);
       $('div.twitter marquee').marquee();
});

var linkHashtags = function (text) {
return text.replace(
    hashtag_regexp,
    '<a class="hashtag" href="http://twitter.com/#search?q=$1">#$1</a>'
    );
} 

【问题讨论】:

    标签: jquery regex json twitter


    【解决方案1】:

    使用twitter-text-js:

    twttr.txt.autoLink("link @user, please #request");
    

    示例:http://jsfiddle.net/44DZ9/

    【讨论】:

    • 只需包含带有&lt;script&gt;标签的脚本并调用twttr.txt.autoLink,仅此而已:)
    • 啊,我明白了,非常感谢。出于某种原因,它似乎没有突出显示#ff,但并不太在意。
    猜你喜欢
    • 2012-01-20
    • 2016-10-02
    • 2013-06-09
    • 1970-01-01
    • 2013-03-12
    • 2011-10-05
    • 1970-01-01
    • 2011-10-14
    • 1970-01-01
    相关资源
    最近更新 更多