【发布时间】:2023-04-04 12:40:01
【问题描述】:
好的,所以我制作了一个运行良好的随机报价生成器。我现在想获取随机生成的报价并将其设为推文。我知道如何使文本成为推文。我的问题是使用生成随机报价的函数并将其添加到推文的 url 中,这是我的代码:
<h1>Random Quote Generator</h1>
<p>Star Wars Quotes</p>
<button class="btn btn-default" type="submit">New Quote</button> <div class="row">
<div class="quote-box col-md-6 col-md-offset-3">
<p class="quote">"Placeholder Quote"</p>
<p class="author">Placheolder Author</p>
<a onclick="getTweet();" href="#" target="_blank"><img src="http://www.iconsplace.com/icons/preview/yellow/twitter-2-256.png" alt="twitter logo"> Use the Force to Tweet</a>
</div><!--quote-box-->
</div><!--row-->
$(document).ready(function() { //random quote works fine
function pickQuote() {
var quotes = ["It's a trap!", "Mmm. Lost a planet, Master Obi-Wan has. How embarrassing.", "I find your lack of faith disturbing"];
var author = ["-Admiral Akbar", "-Yoda", "-Darth Vader"];
var randomNum = Math.floor((Math.random() * quotes.length));
var randomQuote = quotes[randomNum];
var randomAuthor = author[randomNum];
$(".quote").text(randomQuote);
$(".author").text(randomAuthor);
}
$(".btn").on("click", function() {
pickQuote();
});
//this is where the tweet magic is supposed to happen
var a = pickQuote();
function getTweet(){
return "http://twitter.com/home/?status=" + a;
}
});
任何帮助将不胜感激。
【问题讨论】:
标签: javascript jquery html twitter hyperlink