当前位置:  开发笔记 > 编程语言 > 正文

我需要按一个按钮来发推文

如何解决《我需要按一个按钮来发推文》经验,为你挑选了1个好方法。

我正在尝试编写一个"Tweet this"按钮,在Twitter上打开一个带有预生成文本的新窗口.我现在得到的是Twitter上的一个窗口,其中包含我来自哪里的URL.我正在使用JQuery API来执行此操作.我项目的链接是http://codepen.io/haldav/pen/KVpojP.我的代码是:

$(document).ready(function() {
  random();

function random() {
var quotes = ["You must be shapeless, formless, like water. When you pour water in a cup, it becomes the cup. When you pour water in a bottle, it becomes the bottle. When you pour water in a teapot, it becomes the teapot. Water can drip and it can crash. Become like water my friend.", "Defeat is a state of mind; no one is ever defeated until defeat has been accepted as a reality.", "The moment has no yesterday or tomorrow. It is not the result of thought and therefore has no time.", "Real living is living for others.", "Never waste energy on worries or negative thoughts, all problems are brought into existence -drop them.", "A goal is not always meant to be reached. It often serves simply as something to aim at.", "Those who are unaware they are walking in darkness will never seek the light.", "Because one does not want to be disturbed, to be made uncertain, he establishes a pattern of conduct, of thought, a pattern of relationship to man etc. Then he becomes a slave to the pattern and takes the pattern to be the real thing."];

randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
quote = randomQuote.split("randomQuote");
$('.quote').text(quote[0]);
  }

$(".button").on("click", function() {
random();
  });
});

我的HTML代码是:

The Wisdom of Bruce Lee

Although Bruce Lee died at a considerably young age, he was wise beyond his years. For my random quote machine, I chose to showcase some of his wisdom. For this exercise, I used a little JQuery, Bootstrap, CSS and HTML.


Copyright © David C. Hall 2015

我很难过.有什么建议?谢谢.编辑:我正在打开一个新窗口,但我需要它在文本框中显示随机引用.



1> haldav..:

弄清楚了!我所要做的就是添加

$(this).attr("href", 'https://twitter.com/intent/tweet?text=' + randomQuote);

到我的JS代码.

推荐阅读
mobiledu2402852357
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有