[removed] Change label background color on checkbox

后端 未结 7 1448
执笔经年
执笔经年 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

    In addition to the '==' typo mentioned by others, you are also checking whether the label is checked rather than the input. Try:

    function statecheck(layer) {
        var myLayer = document.getElementById(layer),
            input = myLayer.getElementsByTagName('input')[0];
        //myLayer.style.backgroundColor = "#bff0a1";
        if(input.checked == true){
            myLayer.style.backgroundColor = "#bff0a1";
            } else {
            myLayer.style.backgroundColor = "#eee";
        };
    }
    

    jsFiddle: http://jsfiddle.net/7wnCL/26/

    0 讨论(0)
提交回复
热议问题