复选框值始终返回"打开"?

13 forms jquery

我正在尝试返回复选框的值以启用和禁用按钮.使复选框不是问题,问题是复选框值始终返回.我应该如何获得一个值,表明是否选中了复选框?

HTML:

<form>
    <input type="checkbox" id="checkbox" /> <label>Do you agree  </label><br />
    <input type="button" value="Continue" id="button" disabled="disabled" />
</form>  
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

$('#checkbox').change(function(){
    var checkboxValue = $(this).val();
    alert(checkboxValue);
});
Run Code Online (Sandbox Code Playgroud)

Max*_*pan 43

尝试使用prop('checked');

var checkboxValue = $(this).prop('checked');
Run Code Online (Sandbox Code Playgroud)


gdo*_*ica 7

看来你需要 checked

var checkboxValue = this.checked;
Run Code Online (Sandbox Code Playgroud)