字符串+;JavaScript中的增量值

字符串+;JavaScript中的增量值,javascript,html,web,styles,Javascript,Html,Web,Styles,我在代码中间添加了注释。如果可以的话,请帮助我,我今天要送货 if (a === 3) { //this would be how many of the answers further the action var starting = 2; // for an example: yes or no; two of the answers go to no, one goes to yes. //

我在代码中间添加了注释。如果可以的话,请帮助我,我今天要送货

 if (a === 3) { //this would be how many of the answers further the action
                 var starting = 2; // for an example: yes or no; two of the answers go to no, one goes to yes. 
                 //                                  we take 2 as a starting point /you can set these individually for each scenario;
                 if (starting === 2) {
                     for (i = 0; i < starting; i++) {
                         answers[i] = 1; //sets the two checking points of the answer to the no, remaining yes;

 document.getElementById("btn" + i).style.backgroundColor = "red";

     // the problem lies here
    // I tried multiple ways but none of them worked so far
    //i want to apply the style change to multiple buttons at once.

                     }

                     alert(answers);

                     for (i = 0; i < starting; i++) {
                         if (answers[i] == 1) {

                         }
                     }

                 }
             }
如果(a===3){//这将是有多少个答案进一步推动了操作
var start=2;//例如:yes或no;两个答案为no,一个答案为yes。
//我们以2为起点/您可以为每个场景单独设置这些值;
如果(开始===2){
对于(i=0;i
问题是按钮名为btn,按钮名为btn1、btn2、btn3;我希望for循环将其更改为所有按钮,但是id处的字符串文字无法识别I

示例:“btn”+i;=更改btn1的样式

我修好了,伙计们。错误在于for循环从1开始; 我把按钮的id命名错了。新手的错误!:)

(i=0;i<3;i++)的
{
if(document.getElementById(“btn”+i)!=未定义)
document.getElementById(“btn”+i).style.backgroundColor=“红色”;
}


ya。我们当然会帮助你。请添加一些工作示例或标记htmlWhat's error,如果有?
if(starting=2)
需要是
if(starting=2)
um javascript根本没有加载。我也尝试过:document.getElementById(“btn”+I).style.backgroundColor=“red”;工作正常:您是否检查了浏览器控制台中的错误消息?编辑后编辑:听起来你需要
var n=“btn”+(i+2)