[removed] Change label background color on checkbox

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

    the non-jQuery route. pass a second param to your statecheck function.

     
    

    and the javascript

     function statecheck(chk, layer) {
    var myLayer = document.getElementById(layer);
    //myLayer.style.backgroundColor = "#bff0a1";
    if(chk.checked === true){
        myLayer.style.backgroundColor = "#bff0a1";
        } else {
        myLayer.style.backgroundColor = "#eee";
        }
    }
    

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

提交回复
热议问题