私は比較的新しいHTMLですので、私に同行してください。私はすでにFlickrからボタンに画像を取り込むために私に提供されていた単純なjavascript関数を追加しようとしています。ボタンをクリックすると、何も起こりません。私はどこでエラーが発生しているのかわかりませんが、私はそれが正しく実行されていない関数と関係があると思います。ボタンにjavascript機能を追加しようとしています
HTML:
<!DOCTYPE html>
<html>
<head>
<title>getJSON</title>
<meta charset="utf-8" />
<script src="jquery-3.1.1.min.js"></script>
</head>
<body>
<button onclick="myFunction()">Click me</button>
<script>
function myFunction()
{ //Functions don't need names. This function will simply run when the page loads
var flickerAPI = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";
$.getJSON(flickerAPI,
{ // The "$" simply refers to jQuery. This calls the getJSON function that is found inside jquery-3.1.1.min.js
tags: "Baruch College", //Some filter information in the format set by Flickr, who owns the JSON
tagmode: "any",
format: "json"
})
.done(function(data)
{ //Here, a an unnamed function is created made into the event handler for the "done" event... in other words, this is the code that will manifest itself when the getJSON is done.
$.each(data.items, function(i, item)
{
$("<img>").attr("src", item.media.m).appendTo("#images");
if (i === 5)
{
return false;
}
});
});
}
</script>
</body>
</html>
私はHTMLで述べたjqueryのスクリプトをアップロード:http://pastebin.com/2CfRNkvq
ローカルサーバーでページを実行する必要があります。 –
現在実行されているサーバーは何ですか? – user1359783