JS
1$(function(){ 2var likes = null; 3 4$('#like').on('click', function() { 5 getLikes(hotelid).done(function(res) { 6 likes = res.likes; 7 console.log(res); 8 console.log(likes);//NULL 9 if (!$(this).hasClass('liked')) { 10 //今は何もしない 11 12 } 13 }); 14 }); 15});
これを実行するとconsole.log(res)には
[{likes: "234"}] (1)
という値が返ってきますが、console.log(likesを出力するとNULLになります。
どう対処すれば良いですか。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/21 09:17
2019/02/21 09:19
2019/02/21 09:20
2019/02/21 09:23