【发布时间】:2021-08-15 00:49:34
【问题描述】:
我有一个复选框
<input type="checkbox" name="Vebasto" class="checkbox" value="350" id="Vebasto" />
<label for="Vebasto">Vebasto</label>
以及检查是否检查过的脚本:
if(document.querySelector('input#cond').checked = true){
alert("checked");
}
当页面加载时,我收到此警报,但未选中复选框。怎么了?
【问题讨论】:
-
除了其他答案中提到的 assignment 运算符的错误之外,
input#cond似乎不会针对有问题的复选框? (为什么不在这种情况下使用getElementById()?)
标签: javascript html debugging input checkbox