How do I determine if a checkbox is checked?

前端 未结 9 2107
我在风中等你
我在风中等你 2020-11-27 05:23

For some reason, my form does not want to get the value of a checkbox... I am not sure if it is my coding or not, but when I try and alert() the value, I get

9条回答
  •  暖寄归人
    2020-11-27 05:50

    Place the var lfckv inside the function. When that line is executed, the body isn't parsed yet and the element "lifecheck" doesn't exist. This works perfectly fine:

    function exefunction() {
      var lfckv = document.getElementById("lifecheck").checked;
      alert(lfckv);
    }
    
    

提交回复
热议问题