How can I check if a checkbox is checked?

前端 未结 14 1298
轮回少年
轮回少年 2020-11-22 14:28

I am building a mobile web app with jQuery Mobile and I want to check if a checkbox is checked. Here is my code.



        
14条回答
  •  不要未来只要你来
    2020-11-22 14:35

    Try this:

    function validate() {
      var remember = document.getElementById("remember");
      if (remember.checked) {
        alert("checked");
      } else {
        alert("You didn't check it! Let me check it for you.");
      }
    }
    

    Your script doesn't know what the variable remember is. You need to get the element first using getElementById().

提交回复
热议问题