gpt4 book ai didi

javascript - 随机 API 输出?

转载 作者:行者123 更新时间:2023-12-01 01:12:10 25 4
gpt4 key购买 nike

async:true,
dataType: "json",
success: function(response) {
parseArray(response._embedded.events)
},
error: function(xhr, status, err) {
}
});
}
);

function parseArray(response){
for( let i = 0; i < response.length; i++){
createElement("<h2>", response[i].name);
console.log(response[i]);
}
}

function createElement(type, string){
var artistHolder = $("<div>");
var artist = $(""+type);

$(artist).text(string);
artistHolder.append(artist);
//append div to container
$("#container").append(artistHolder);

}

所以我试图随机化我附加到容器的响应,但我所有尝试使用 Math.floor(Math.random())已经空了...我尝试过使用 API 的端点,但这也没有帮助我。我对这一切都很陌生......上面的代码只是一遍又一遍地附加相同的响应。感谢您提前提供的帮助(如果有)。

最佳答案

Math.random() 返回 [0..1[ 范围内的值 - 当你将其取整时,你将始终得到 0要获得 0..1000 范围内的数字,您必须在执行下限之前将其相乘。

使用例如

Math.floor(Math.random() * 1000)

关于javascript - 随机 API 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55070757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com