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条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看