【发布时间】:2017-06-09 22:17:44
【问题描述】:
我有一个随机报价生成器 (http://codepen.io/anon/pen/wgqWgo),在尝试发布报价时,我得到以下结果:
我没有正确链接我在我的函数中假设的报价。作为 JavaScript 新手,很难说是什么。我对此进行了广泛搜索,似乎找不到解决方案。
我的 HTML:
<div class="row">
<div class="col-12 buttons">
<a class="twitter-share-button" href="http://twitter.com/share" target="_blank"><button type="button" class="btn btn-outline-danger" onclick="tweetIt()"><i class="fa fa-twitter" aria-hidden="true"></i></button></a>
<button type="button" class="btn btn-outline-danger" onclick="newQuote()">Quote</button>
</div>
</div>
<div class="row">
<div class="col-12">
<div id="quoteDisplay" class="writing">
<!-- Quotes here -->
</div>
</div>
</div>
我的 JavaScript:
var quotes = [
"There is nothing to writing. All you do is sit down at a typewriter and bleed.",
"Happiness in intelligent people is the rarest thing I know.",
"The world breaks everyone, and afterward, some are strong at the broken places."
]
function newQuote() {
var randomNumber = Math.floor(Math.random() * (quotes.length));
document.getElementById('quoteDisplay').innerHTML = quotes[randomNumber];
};
$(".twitter-share-button").click(function(){
$(this).attr("href", 'https://twitter.com/intent/tweet?text=' + randomNumber);
});
【问题讨论】:
标签: javascript jquery html twitter-bootstrap twitter