【发布时间】:2017-09-22 02:33:36
【问题描述】:
我正在通过Free Code Camp's "Random Quote Machine" 工作,并且我构建了一个非常(强调非常)基本的模型,但是我无法弄清楚如何使用我的代码的方式获取引号和推文。我是否必须更改我当前的 Javascript 代码才能发推文,或者有没有办法用我没有意识到的当前代码发送推文?我知道有一个another question like this 有解决方案,但是我不明白。非常感谢。
var quotes= [
'I love you the more in that I believe you had liked me for my own sake
and for nothing else. John Keats',
'But man is not made for defeat. A man can be destroyed but
not defeated. Ernest Hemingway',
'When you reach the end of your rope, tie a knot in it and
hang on. Franklin D. Roosevelt',
'Always do what is right. It will gratify half of mankind
and astound the other. ― Mark Twain',
'Whenever you find yourself on the side of the majority, it
is time to pause and reflect. Mark Twain',
'It is curious that physical courage should be so common in
the world, and moral courage so rare.- Mark Twain in Eruption',
'A man should not be without morals; it is better to have
bad morals than none at all.- Mark Twain\'s Notebook',
'The most permanent lessons in morals are those which come,
not of book teaching, but of experience.- A Tramp Abroad',
'But the fact that he can do wrong proves his moral
inferiority to any creatures that cannot.― Mark Twain',
'\“Wrong does not cease to be wrong because the majority
share in it.\” ― Leo Tolstoy',
'\“Right is right even if no one is doing it; wrong is wrong
even if everyone is doing it.\” ― Augustine of Hippo'
]
function nextQuote() {
var randomNumber = Math.floor(Math.random()*quotes.length);
document.getElementById("displayQuote").innerHTML = quotes[randomNumber];
}
<h1>Random Quote Machine</h1>
<!--Javascript will go in div-->
<div>
<h2 id="displayQuote"></h2>
</div>
<button onclick="nextQuote()">New Quote</button>
<button id="tweetQuote"><a>Tweet</a></button>
【问题讨论】:
标签: javascript twitter event-handling dom-events