我有一個隨機報價發生器(http://codepen.io/anon/pen/wgqWgo),並試圖鳴叫報價的時候,我得到以下結果:Twitter的按鈕不啁啾正確
我沒有連接我的報價正確我承擔我的功能。對於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);
});
既然你放在Twitter的按鈕withing的元素,目標是覆蓋您在JavaScript中的實際鏈接。 Twitter默認文本到你來自的URL,即:https://twitter.com/intent/tweet?url=&original_referer= –