1
だから、うまく動作するランダムなクォートジェネレータを作った。私はランダムに生成された見積もりをとり、それをツイートにしたいと考えています。私はテキストをつぶす方法を知っています。私の問題は、ランダムな見積もりを生成する関数を取り、ここでつぶやくへのURLに追加されたことは私のコードです:Twitter URLのリンク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;
}
});
任意の助けをいただければ幸いしてください。
おかげで多分私は、HTMLの多くを追加している必要があります。ボタン(.btn)は引用符をランダム化し、引用符付きのhtmlがhtmlの前にhtmlをもう一度チェックする前にhtmlにあります。そのdivの前の行に追加して、鮮明な画像を得ることができます – MikeL5799