douwen1213 2012-05-24 13:00
浏览 51
已采纳

获取<div>中的文本并输出

I'm building a section which uses the jQuery UI to allow users to drag words around on screen to create their own sentences, which they can then share on Twitter.

I'm wanting the text they create to be inputted into the Twitter text area when they click the 'Tweet' button.

I'm hoping that, with PHP or JS, there would be a way to output the text that's been moved into the div, then input it into the '&text=Text%20goes%20here' part of the Twitter code.

<a href="https://twitter.com/intent/tweet?button_hashtag=SUYearbook&text=Text%20goes%20here" 
   class="twitter-hashtag-button" data-size="large" 
   data-related="username">Tweet #SUYearbook</a>

You can see the set up here if you need to understand anything further: http://goo.gl/s6CBD

To reiterate: Drag text into area, on pressing the Tweet button (or a 'finish' button), it adds the text contents to the Twitter code and then it's there in the tweet modal.

  • 写回答

2条回答 默认 最新

  • dongxiqian2787 2012-05-24 13:05
    关注

    The simplest way would be to add a class to the span of each word on drop into the area, and then loop through each span with the appropriate class. Something like this:

    $(".twitter-hashtag-button").click(function(e) {
        e.preventDefault();
        var text = $(".selectedWord").map(function() {
            return $(this).text();
        }).get().join(' ');
        window.location.assign("https://twitter.com/intent/tweet?button_hashtag=SUYearbook&text=" + text)
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)