为什么闪烁的API标签不能获得输入值?

时间:2017-03-09 15:46:34

标签: javascript jquery json api

为什么,当我在var title = $("myInput").value()输入时,API标记无法获得价值?如果我直接插入值 - var title = "some text",它就可以了!



(function() {
    var flickerAPI = "https://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?&api-key=d1c0be70688307ed71f305474f32c559&secret=04bb4c80a0753d23";
    $("#submit").click(function() {
        var title = $("myInput").value();
        $.getJSON(flickerAPI, {
          tags: title,
          tagmode: "all",
          format: "json"
        }).done(function(data) {
          $.each(data.items, function(i, item) {
            $("<img>").attr("src", item.media.m).appendTo("#images");
            if (i === 3) {
              return false;
            }
          });
        });
      }
    });
  });
};
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">

<head>
  <title>FlowersApp</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" type="text/css" href="flowerStyle.css">
  <script type="text/javascript" src="jquery-3.1.1.min.js"></script>
  <script type="text/javascript" src="getvalJavaScript.js"></script>
</head>

<body>
  <div class="center" id="images"> </div>
  <div id="inputDiv">
    <input type="text" id="myInput" placeholder="Title..." value="">
    <button id="submit"> submit</button>
  </div>
</body>

</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

简单的拼写错误...你缺少哈希,它将目标识别为ID:

var title = $("#myInput").value();