错误检查属性“false”

时间:2010-04-19 07:06:45

标签: javascript validation checkbox

我使用此javascript语法验证复选框...

 alert(document.getElementById("ctl00_ContentPlaceHolder1_Chkreg").checked);
  if (document.getElementById("ctl00_ContentPlaceHolder1_Chkreg").checked == false) {
        document.getElementById("ctl00_ContentPlaceHolder1_ErrorMsg").innerHTML = "please select the checkbox";
        document.getElementById("ctl00_ContentPlaceHolder1_Chkreg").focus();
        return false;
    }

我的警告显示我是假的但是我的if循环不起作用......任何建议......

1 个答案:

答案 0 :(得分:4)

假设您的盒子没有被选中,我会亲自把它写成:

var box = document.getElementById("ctl00_ContentPlaceHolder1_Chkreg");
if (!box.checked) {
    document.getElementById("ctl00_ContentPlaceHolder1_ErrorMsg").innerHTML = "please select the checkbox";
    box.focus();
    return false;
}