【问题标题】:Take Value of DIV and Post to Twitter获取 DIV 的值并发布到 Twitter
【发布时间】:2011-03-24 03:22:16
【问题描述】:

我正在使用 Jquery 开发一款游戏,并希望获取 DIV(分数)的内容并将其发布到 Twitter:

    <div id="score">
    <p>You scored <span class="scoreToPost">800 points</span>!</p>
    <p>Click <a href="">here</a> to post to Twitter</p>
    </div><!--end score-->

然后在用户选择发布到 Twitter 后,它会在 Twitter 弹出框中显示如下内容:

@User:“我刚刚在这款酷游戏中获得了 800 分!#CoolGameTitle”

我的问题是我不知道如何使用 Twitter 按钮 API 来获取跨度内的分数并预填充 Twitter 字段?有什么想法吗?

谢谢。

【问题讨论】:

    标签: jquery api twitter


    【解决方案1】:

    如果只需要解析html获取分数,可以使用:

    var html = $('.scoreToPost').html();
    
    var matches = html.match(/^(\d+).*$/);
    var score = matches[1];
    alert(score);
    

    演示:http://jsfiddle.net/ZfsWr/

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-05
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多