Toggle Checkbox using JavaScript

后端 未结 5 2122
栀梦
栀梦 2021-02-06 06:07

I had this working, but I didnt save and cannot replicate. I am trying to toggle checkboxes using if else. What am I doing wrong.

What I thought would work

5条回答
  •  情书的邮戳
    2021-02-06 06:36

    Single equals is assignment, double/triple equals is for equality. You need to use double or triple equals in your if/else block.

        if(inputs[i].checked == false) {
            inputs[i].checked = true; 
        }
        else {
            if(inputs[i].checked == true) {
                inputs[i].checked = false; 
             }   
        }
    

提交回复
热议问题