我试图检查天气复选框被选中或未选中。这是我的代码:如何检查复选框选中或未选中JavaScript?
<script type="text/javascript">
function EnableDisableToolTip() {
if (document.forms[0].help_text.checked) {
alert("Checked");
}
else if (!document.forms[0].help_text.checked) {
alert("Unchecked");
}
}
</script>
<div id="tooltiponoff">
<form action="">
@Html.CheckBox("help_text", true, new { id = "help_text", onclick = "EnableDisableToolTip()" })Hjælpetekst
</form>
</div>
它只是提醒未选中时,我提前点击
感谢
可能重复[JavaScript来检查一个复选框是否被选中或取消选中(http://stackoverflow.com/questions/473562/javascript-to-check-whether- a-checkbox-is-being-checked-or-unchecked) –
检查'alert(document.forms [0] .help_text)'给出..?如果未定义,可能会始终处于其他情况。 – niksvp