gpt4 book ai didi

javascript - 带按钮创建的功能轮询

转载 作者:行者123 更新时间:2023-11-28 19:41:48 28 4
gpt4 key购买 nike

我写了一个 jQuery 脚本。正如我所想,这应该从 JSON 中获取 templateTotal 的数量(USB 上存在的模板总数)并生成尽可能多的按钮,如下所示templateTotal 表示。

例如,如果 templateTotal6,则脚本应生成 6 个按钮。

(function poll() {
setTimeout(function () {
$.ajax({
type: "GET",
url: "/api/status",
processData: true,
dataType: 'text',
cache: false,
success: function (data, textStatus, request) {
var template = jQuery.parseJSON(data);
var templateButton = "";
for (i = 1; i > templateTotal; i++);
templateButton += '<button class="templateButton" id="T' + i + '" formaction="/api/template" post="template=' + i + '">T' + i + '</button>'
},
complete: poll
});
});
})();

最佳答案

for 循环后有一个分号:

 for(i=1; i > templateTotal; i++);

应该是:

 for(i=1; i > templateTotal; i++)
templateButton += '<button class="templateButton" id="T'
+ i +'"
formaction="/api/template"post="template='+i+'">T'+i+'</button>'

for(i=1; i > templateTotal; i++){
templateButton +=
'<button class="templateButton" id="T' + i +
'" formaction="/api/template"
post="template='+i+'">T'+i+'</button>'
}

分号表示语句的结束(与回车符一样)。 for 循环(除非后跟括号)将执行下一个以分号结束的语句。

分号并不是结束语句所必需的,但最好将其放入。省略分号仍会创建有效的语法。

关于javascript - 带按钮创建的功能轮询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24911423/

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