oncheck listener for javascript中的复选框

Got*_*teh 15 html javascript dom

我的表单底部有这样的代码.

<p>
  <input type="checkbox" id="agreed">
  I agree to keep my Username and Password confidential and uphold 
  the integrity of this pharmacy
</p>
<input type="submit" id="submit" disabled class="formbutton button-primary" value="Go">
Run Code Online (Sandbox Code Playgroud)

我希望这个JavaScript中的监听器能够启用提交按钮.我知道它可能是错误的,但我的JavaScript看起来有点像这样

function track() {
    if ( document.getElementById("agreed").checked==true ) {
        document.getElementById("submit").removeAttribute("disabled");
    } else {
        document.getElementById("agreed").checked==false
    }
};
Run Code Online (Sandbox Code Playgroud)

Lvk*_*vkz 29

您可以为输入执行此操作:

<input type='checkbox' onchange='handleChange(this);'>Checkbox
Run Code Online (Sandbox Code Playgroud)

这用于启用按钮:

function handleChange(checkbox) {
    if(checkbox.checked == true){
        document.getElementById("submit").removeAttribute("disabled");
    }else{
        document.getElementById("submit").setAttribute("disabled", "disabled");
   }
}
Run Code Online (Sandbox Code Playgroud)