按钮的onClick()事件没有指向任何地方.ajax的success()可能存在一些问题.我无法弄清楚我对此是什么新手.
var currentAuthor="";
var currentQuote="";
$(document).ready(function(){
$("#getMessage").on("click",function(){
$.ajax({
header:{
"X-Mashape-Key":"xE5Raw3acMmsh4dpp6HEk5WSbJtTp1X9TL3jsnue3VRzr5vNNa",
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
url:"https://andruxnet-random-famous-quotes.p.mashape.com/?cat=",
success: function(response){
var r=json.parse(response);
currentQuote=r.quote;
currentAuthor=r.author;
$("#author").html(r.author);
}
});
});
});
Run Code Online (Sandbox Code Playgroud) 似乎编译器没有进入for循环.数组的总和是计算的.SumAll([1,4])应该返回10(1 + 2 + 3 + 4)作为输出.
function sumAll(arr) {
//return Math.max.apply(Math,arr);
//return Math.min.apply(Math,arr);
// return "0";
var sum=arr.reduce(function(a,b){
for(var i=Math.min.apply(Math,arr);i<=Math.max.apply(Math,arr);i++){
return a+b;
}
},0);
//return sum;
}
sumAll([1, 4]);
Run Code Online (Sandbox Code Playgroud)