允许我的推文按钮分享随机引述

Allowing my tweet button to share the random quotes

大家早上好,我知道之前有人问过这个问题,但作为 Javascript 的新手,我正在努力学习,我无法理解如何让我的 Twitter 按钮分享随机引述.如果可能的话,好心的开发人员可以向我解释如何实际输入它。我对 HTML、CSS 和 Bootstrap 有很好的理解,但希望有人能向我解释一下。

非常感谢。

var quotes = [
  "\'It is never too late to be what you might have been.\' - George Eliot",
  "\'What lies behind us and what lies before us are tiny matters compared to what lies within us.\' - Henry Stanley Haskins",
  "\'Great thoughts speak only to the thoughtful mind, but great actions speak to all mankind.\' - Emily P. Bissell",
  "\'I haven’t failed. I’ve just found 10,000 ways that don’t work.\' - Thomas Edison",
  "\'In between goals is a thing called life, that has to be lived and enjoyed.\' - Sid Caesar"
]
function newQuote() {
  var randomNumber = Math.floor(Math.random() * (quotes.length));
  document.getElementById('quoteDisplay').innerHTML = quotes[randomNumber];
}
<html>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<body>
  
  
  <h1>Simple Quote Generator</h1>
  <div id="quoteDisplay">
  </div>
    
  <div class="quoteButton">
  <button onclick="newQuote()">New Quote</button>
   
  </div>
  <a href="http://twitter.com/intent/tweet/?text" title="Share on Twitter" target="blank" class="btn btn-twitter-"><i class="fa fa-twitter"></i> Twitter</a>
  <script src="javascript.js"></script>
</body>
</html>

你的 link 的目标是静态的,总是 twitter.com/intent/tweet/?text。我不熟悉 Twitter API,但我猜它希望在 URL 末尾有类似 ?text=some&encoded&text 的内容。 您需要设置文本的值:

<a href="" id="twitterLink">

function newQuote() {
  var randomNumber = Math.floor(Math.random() * (quotes.length));
  document.getElementById('quoteDisplay').innerHTML = quotes[randomNumber];

  document.getElementById('twitterLink').href = "http://twitter.com/intent/tweet/?text=" + encodeURIComponent(quotes[randomNumber])

}
<span class="tweetquote" style="margin:15px; padding:15px; border:1px solid #ddd;">
<a  href="https://twitter.com/intent/tweet?url=https://twitter.com&;text=Tweet This piece of content the Entire quote in content and its url&;via=twitter&;" title="Tweet This piece of content the Entire quote in content and its url" target="_blank" rel="noopener noreferrer">Tweet This piece of content the Entire quote in content and its url</a>
<a href="https://twitter.com/intent/tweet?url=https://twitter.com&;text=Tweet This piece of content the Entire quote in content and its url&;via=twitter&;" title="Tweet This piece of content the Entire quote in content and its url" target="blank" class="btn btn-twitter-"><i class="fa fa-twitter"></i>Tweet</a>