Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 随机报价机或推特当前报价不';行不通_Javascript_Jquery_Html_Json - Fatal编程技术网

Javascript 随机报价机或推特当前报价不';行不通

Javascript 随机报价机或推特当前报价不';行不通,javascript,jquery,html,json,Javascript,Jquery,Html,Json,jQuery on click函数推特当前报价不想工作。这里出了什么问题。我必须建立随机报价机和推特当前报价。我已经设法做了JSON API,但不知道如何推特当前的报价。请帮忙 HTML: <div class="container-fluid"> <div class = "well"> <div class="row"> <h2 class="text text-center"><i class="fa fa-quote-left"

jQuery on click函数推特当前报价不想工作。这里出了什么问题。我必须建立随机报价机和推特当前报价。我已经设法做了JSON API,但不知道如何推特当前的报价。请帮忙

HTML

<div class="container-fluid">
<div class = "well">


<div class="row">

<h2 class="text text-center"><i class="fa fa-quote-left"> </i> Hey, what when and why there is no and yes?</h2>


<p class="author">-Alina Khachatrian</p>



<div class="buttons">
  <div class="row">
    <div class="col-xs-6">
      <a id="tweet-quote" title="Tweet current quote" target="_blank" href="#">
        <i class="fa fa-twitter fa-2x"></i>
      </a> 
 </div>
 <div class="col-xs-6">
   <button type="button"  class="btn btn-default btn-transparent" id ="getNewQuote" title="Get a new quote">New Quote</button>
 </div>
</div>
<footer class="text-center">
<hr>
<p>Written and coded by <a href="https://github.com/edkiljak">Edgar Kiljak</a>.</p>
</footer>  
</div>
</div>
 $(document).ready(function(){
    $(".btn").on("click", function(){
        $.getJSON("http://quotes.stormconsultancy.co.uk/quotes.json", function (json) {

  var html = "";
  var len = json.length;
  var index = Math.floor(Math.random() * len);
  var val = json[index];

  html += "<div class = 'newQuote'>";

  html += "<h3>'" + val.quote + "'</h3>";


  html += "</div>";
  $(".author").text(val.author);

  $(".text").html(html);

    $('#tweet-quote').on("click",function(){
       window.open("https://twitter.com/intent/tweet?text="+
      $(val.quote).text() +"&via=your-app-name&original_referer=your-url");
     });

   });
 });
});

嘿,什么时候,为什么没有和是?

-Alina Khachatrian

新报价
由……编写和编码

JS

<div class="container-fluid">
<div class = "well">


<div class="row">

<h2 class="text text-center"><i class="fa fa-quote-left"> </i> Hey, what when and why there is no and yes?</h2>


<p class="author">-Alina Khachatrian</p>



<div class="buttons">
  <div class="row">
    <div class="col-xs-6">
      <a id="tweet-quote" title="Tweet current quote" target="_blank" href="#">
        <i class="fa fa-twitter fa-2x"></i>
      </a> 
 </div>
 <div class="col-xs-6">
   <button type="button"  class="btn btn-default btn-transparent" id ="getNewQuote" title="Get a new quote">New Quote</button>
 </div>
</div>
<footer class="text-center">
<hr>
<p>Written and coded by <a href="https://github.com/edkiljak">Edgar Kiljak</a>.</p>
</footer>  
</div>
</div>
 $(document).ready(function(){
    $(".btn").on("click", function(){
        $.getJSON("http://quotes.stormconsultancy.co.uk/quotes.json", function (json) {

  var html = "";
  var len = json.length;
  var index = Math.floor(Math.random() * len);
  var val = json[index];

  html += "<div class = 'newQuote'>";

  html += "<h3>'" + val.quote + "'</h3>";


  html += "</div>";
  $(".author").text(val.author);

  $(".text").html(html);

    $('#tweet-quote').on("click",function(){
       window.open("https://twitter.com/intent/tweet?text="+
      $(val.quote).text() +"&via=your-app-name&original_referer=your-url");
     });

   });
 });
});
$(文档).ready(函数(){
$(“.btn”)。在(“单击”,函数(){
$.getJSON(“http://quotes.stormconsultancy.co.uk/quotes.json,函数(json){
var html=“”;
var len=json.length;
var index=Math.floor(Math.random()*len);
var val=json[index];
html+=“”;
html+=“'”+val.quote+“”;
html+=“”;
$(“.author”).text(val.author);
$(“.text”).html(html);
$('#tweet quote')。在(“单击”,函数(){
窗口打开(“https://twitter.com/intent/tweet?text="+
$(val.quote).text()+“&via=您的应用程序名和原始\ u referer=您的url”);
});
});
});
});

我遇到的第一个问题是,我甚至看不到Tweet当前报价的链接。我必须在锚中添加文本:

  <a id="tweet-quote" title="Tweet current quote" target="_blank" href="#">
    <i class="fa fa-twitter fa-2x"></i>
  TWEET CURRENT QUOTE
  </a> 
第四:如果您加载第二个“新报价”,然后单击“Tweet This Quote”,您将看到它打开两个新窗口——它同时推送旧报价和新报价。这是因为(“单击”)上的
是累积的。在设置新函数之前,应清除任何现有函数:

$('#tweet-quote').unbind("click");
$('#tweet-quote').on("click",function(){
   window.open ... 

第五:通常当你在这里发布问题时,“不起作用”并不是一个充分的解释。你应该解释什么不起作用,或者什么与你希望的不同。错误消息(如果有)。您在控制台日志中看到的内容。有些人对此很反感。有些人可能会对我帮你做作业感到不安。祝你好运

非常感谢你,艾伦。我还试图将val.quote+“&via=your app name&original_referer=your url”替换为报价后的#myfavoritequote。你能帮我解决这个问题吗?好的,你应该试试:
val.quote+“#myfavoritequote+”&via..
看到当推特页面出现时,标签不见了。这是因为#是一个需要封装的特殊字符。
val.quote+encodeURIComponent(“#myfavoritequote')+”&via=
可以工作。事实上,你可能会看到机器人的一些引用包含特殊字符,导致推特在推特页面上被切断。您可以使用
encodeURIComponent(val.quote)
解决这个问题。非常感谢!非常感谢!