gpt4 book ai didi

javascript - 在for循环中声明多个变量

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

我试图在 for 循环中声明多个变量,但我这样做的方式不起作用,我试图搜索类似的问题但找不到...

 for (var n = 0;  n < 10; n++) 
{
var b + n = document.getElementById("b" + n);
}

最佳答案

尝试使用数组

var b = new Array();
for (var n = 0; n < 10; n++)
{
b[n] = document.getElementById("b" + n);
}

关于javascript - 在for循环中声明多个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50915401/

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