[removed] Change label background color on checkbox

后端 未结 7 1445
执笔经年
执笔经年 2021-01-25 06:37

I am trying to change the background color of a label in each checkbox in a form based on the checked/unchecked state of the checkbox.So far I got it to change initially, but it

7条回答
  •  鱼传尺愫
    2021-01-25 07:08

    http://jsfiddle.net/7wnCL/20/

    myLayer.checked = true
    

    is an assignment, not a condition.

    if (myLayer.checked = true)
    

    is every time evaluated as

    if (true)
    

    And the else part will never be executed. So change it to:

    if (myLayer.checked === true)
    

    Also, you should check for the input, and not for the layer, which doesn't have any checked property:

    if (myLayer.childNodes[0].checked === true)
    

提交回复
热议问题