Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用twitter api推送html元素';内容_Javascript_Html - Fatal编程技术网

Javascript 使用twitter api推送html元素';内容

Javascript 使用twitter api推送html元素';内容,javascript,html,Javascript,Html,我正在尝试创建一个随机引用生成器,然后使用tweet按钮推送当前引用(元素的内容),但我只能使用twitter api推送url,我已经研究和阅读了,但完全被卡住了。任何帮助都将非常棒! 这是带有twitter按钮的HTML <body> <h1>J.R.R. Tolkien Quote Machine!</h1> <div id ="stuff"> <img id="image" src="http://i1376.photobucket

我正在尝试创建一个随机引用生成器,然后使用tweet按钮推送当前引用(元素的内容),但我只能使用twitter api推送url,我已经研究和阅读了,但完全被卡住了。任何帮助都将非常棒! 这是带有twitter按钮的HTML

<body>
<h1>J.R.R. Tolkien Quote Machine!</h1>

<div id ="stuff">
<img id="image" src="http://i1376.photobucket.com/albums/ah30/joecarlowittosi/images_zpsukywovht.jpg">
<h2 id = "quotetext">Press the button to discover the first quote.</h2>

<button id = "quotebutton" onclick = "randomQuote()">Get a new quote...      </button>

</div>
<!--tweet the url-->
<a href="https://twitter.com/share" class="twitter-share-button" data-show-count="false">Tweet</a><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>


</body>

你看了所有的东西了吗?当然,我尝试了很多不同的东西,搜索了twitter api站点,但找不到一种方法将我的元素的内容变成一个tweet抱歉,我是说元素我也尝试过这个(这没有解决问题!)$(“#quotetext”).text(data.quotetext);var quot=''+data.quotetext$(“.twitter共享按钮”).attr(“href”,quot);
var myQuotes = [
  "'Faithless is he that says farewell when the road darkens.'",
  "'All we have to decide is what to do with the time that is given us.'",
  "'If more of us valued food and cheer and song above hoarded gold, it would be a merrier world.'",
  "'Never laugh at live dragons.'",
  "'There is some good in this world, and it's worth fighting for.'",
  "'Faithless is he that says farewell when the road darkens.'",
  "'The world is indeed full of peril, and in it there are many dark places; but still there is much that is fair, and though in all lands love is now mingled with grief, it grows perhaps the greater.'",
  "'Many that live deserve death. And some that die deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement.'",
  "'Not all those who wander are lost.'",
  "'I will not say: do not weep; for not all tears are an evil.'",
  "'Little by little, one travels far'",
  "'Courage is found in unlikely places.'",
  "'It's the job that's never started as takes longest to finish.'",
  "'There is nothing like looking, if you want to find something. You certainly usually find something, if you look, but it is not always quite the something you were after.'",
  "'The wide world is all about you: you can fence yourselves in, but you cannot forever fence it out.'",
  "'It may be the part of a friend to rebuke a friend's folly.'",
]
var myImages = [
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/p0232nkj_zpsevgnb5vx.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/lord-of-the-rings-quiz-orig_zpsse5k5mrg.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/12d212546fbb50f1f278db8d3c893b05_zpsqzlpz91p.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/imgres1_zpsdsmi4elj.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/samwise-gamgee_zpsrhuv2u33.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/p0232nkj_zpsevgnb5vx.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/images2_zpsgyxpexod.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/gollum_zpsy583lrzv.png",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/images_zpsonmjtyty.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/imagesq_zpsfgguq2ha.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/imgres_zpsesxdolbh.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/images_zps9qwoibjr.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/imgresw_zpseizew5r4.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/The-Hobbit-An-Unexpected-Journey-2012-1_zpsjxz1lw9i.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/middleearthlargelargerstill_zpscp5xil1m.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/lord_of_the_rings-_the_fellowship_of_the_ring_wallpaper_15_1024_zpssafzudw9.jpg"
]

function randomQuote() {
  var randomNumber = Math.floor(Math.random() * (myQuotes.length));
  document.getElementById("quotetext").innerHTML = myQuotes[randomNumber];
  document.getElementById("image").src = myImages[randomNumber];
}