0
我擁有的是「隨機報價生成器」。顧名思義,它會在點擊按鈕時生成隨機引號。在我的這個所謂的應用程序中,我有一個應該在Facebook牆上發佈'生成的引號'的按鈕。同樣的事情在我的推特按鈕的情況下工作順利,而我不能在臉書的情況下這樣做。在Facebook上發佈文本按鈕點擊
<script>
$(document).ready(function(){
\t //alert("hi");
\t $.getJSON("https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=40",function(json){
\t \t //alert("hello");
\t \t var colour_arr = ["YellowGreen","Turquoise","Tomato","Teal","SteelBlue","SlateBlue","SeaGreen","SandyBrown","Red","Purple","PaleVioletRed","PaleGreen","Orange","MediumVioletRed","MediumTurquoise","Magenta","LimeGreen","LightSalmon","Khaki","Gold","DodgerBlue","DeepPink","DarkOrange","Crimson","Aquamarine"];
\t \t var colour_num = 0;
\t \t var num = 0;
\t \t var html_quote = "";
\t \t /*json.forEach(function(val){
\t \t \t html += "<h3 id='quote'>" + val.content + "</h3>";
\t \t });*/
\t \t var html_author = "";
\t \t html_quote = "<h3 id='quote' class='colour'><i class='fa fa-quote-left' aria-hidden='true'></i>" + json[num].content + "</h3>";
\t \t html_author = "<h5 id='author' class='colour'> - " + json[num].title + "</h5>";
\t \t $("#quote-column").html(html_quote);
\t \t $("#author-column").html(html_author);
\t \t $(".colour").css("color",colour_arr[colour_num]);
\t \t $(".bg-colour").css("background-color",colour_arr[colour_num]);
\t \t $("#new-quote-btn").on("click",function(){
\t \t \t //alert("hello");
\t \t \t colour_num++;
\t \t \t num++;
\t \t \t //alert(num);
\t \t \t html_quote = "<h3 id='quote' class='colour'><i class='fa fa-quote-left' aria-hidden='true'></i>" + json[num].content + "</h3>";
\t \t \t html_author = "<h5 id='author' class='colour'> - " + json[num].title + "</h5>";
\t \t \t $("#quote-column").html(html_quote);
\t \t \t $("#author-column").html(html_author);
\t \t \t $(".my-btn").css("color","white");
\t \t \t $(".colour").css("color",colour_arr[colour_num]);
\t \t \t $(".bg-colour").css("background-color",colour_arr[colour_num]);
\t \t });
\t \t var randomQuote = json[num].content.replace("<p>","");
\t \t randomQuote = randomQuote.replace("</p>","");
\t \t $("#twitter-btn").on("click",function(){
\t \t \t //alert(json[num].content);
\t \t \t //var randomQuote = json[num].content.replace("<p>","");
\t \t \t //randomQuote = randomQuote.replace("</p>","");
\t \t \t //alert(randomQuote);
\t \t \t window.open("https://twitter.com/intent/tweet?text=" + randomQuote,"_blank");
\t \t \t //location.href = "https://twitter.com/intent/tweet?text=" + json[num].content;
\t \t \t //$(this).attr("href","https://twitter.com/intent/tweet?text=" + json[num].content);
\t \t });
\t \t $("#fb-btn").on("click",function(){
\t \t \t window.open("https://www.facebook.com/sharer/sharer.php?u=https://codepen.io/iamrkcheers/pen/gRjoeZ","_blank");
\t \t });
\t });
});
</script>
.box {
\t background-color : white;
\t border-radius : 5px;
}
.my-btn {
\t color : white;
}
#twitter-btn, #fb-btn {
\t width : 40px;
}
<html>
<body class="bg-colour">
\t <div class="container-fluid">
\t \t <div class="row" id="main-row">
\t \t \t <div class="col-md-12 col-sm-12 col-xs-12" id="main-column">
\t \t \t \t <br>
\t \t \t \t <br>
\t \t \t \t <br>
\t \t \t \t <br>
\t \t \t \t <br>
\t \t \t \t <br>
\t \t \t \t <div class="row" id="row-containing-block">
\t \t \t \t \t <div class="col-md-offset-4 col-md-4 col-sm-offset-3 col-sm-6 col-xs-offset-1 col-xs-10 box" id="column-containing-block">
\t \t \t \t \t \t <br>
\t \t \t \t \t \t <div class="row" id="quote-row">
\t \t \t \t \t \t \t <div class="col-md-offset-1 col-md-10 col-sm-offset-1 col-sm-10 col-xs-offset-1 col-xs-10" id="quote-column">
\t \t \t \t \t \t \t \t <!-- <h3 id="quote"></h3> -->
\t \t \t \t \t \t \t </div>
\t \t \t \t \t \t </div>
\t \t \t \t \t \t <div class="row" id="author-row">
\t \t \t \t \t \t \t <div class="col-md-offset-7 col-md-4 col-sm-offset-5 col-sm-6 col-xs-offset-3 col-xs-8" id="author-column">
\t \t \t \t \t \t \t \t <!-- <h5 id="author"></h5> -->
\t \t \t \t \t \t \t </div>
\t \t \t \t \t \t </div>
\t \t \t \t \t \t <br>
\t \t \t \t \t \t <div class="row" id="btn-row">
\t \t \t \t \t \t \t <div class="col-md-offset-1 col-md-10 col-sm-offset-1 col-sm-10 col-xs-offset-1 col-xs-10" id="btn-column">
\t \t \t \t \t \t \t \t <button type="button" class="btn btn-default my-btn bg-colour" id="twitter-btn"><i class="fa fa-twitter" aria-hidden="true"></i></button>
\t \t \t \t \t \t \t \t <button type="button" class="btn btn-default my-btn bg-colour" id="fb-btn"><i class="fa fa-facebook" aria-hidden="true"></i></button>
\t \t \t \t \t \t \t \t <button type="button" class="btn btn-default my-btn bg-colour pull-right" id="new-quote-btn">New Quote</button>
\t \t \t \t \t \t \t </div>
\t \t \t \t \t \t </div>
\t \t \t \t \t \t <br>
\t \t \t \t \t </div>
\t \t \t \t </div>
\t \t \t \t <br>
\t \t \t \t <br>
\t \t \t \t <br>
\t \t \t \t <br>
\t \t \t \t <br>
\t \t \t \t <br>
\t \t \t </div>
\t \t </div>
\t </div>
</body>
</html>
以下是我工作的例子..
https://codepen.io/iamrkcheers/pen/gRjoeZ
取而代之的是 「說說這個。」 的文字,我想我的 '隨機報價'。 無論如何要做到這一點?!? Anyhelp表示感謝。 謝謝。
我正在尋找在JavaScript的響應! – iamrkcheers