我的验证表格Dosent工作,我不知道为什么?

时间:2017-01-30 23:46:55

标签: javascript html

我的验证表格Dosent工作,我不知道为什么它似乎没问题



     function Validator(){
            if(document.shahab_Form.TheCheckBox.checked)
            {
                alert("it's already Checked my Friend!");
            }
            else
            {
             alert("no it's not checked my friend");
            }
        }

    <form name="Shahab_Forms">
            <input type="checkbox" name="TheCheckBox"/>
            <input type="button" value="Press Me" onclick="Validator();"/> 
    </form>

  
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

JavaScript是区分大小写的。 Shahab_Formsshahab_forms不同。 您的代码中有2个错误:

1)caseSenstivity,即shahab_FormsShahab_Forms

2)您输入了错字:shahab_Form。您最后错过了“ s”。

下面是您的工作代码

 function Validator(){
            if(document.Shahab_Forms.TheCheckBox.checked)
            {
                alert("it's already Checked my Friend!");
            }
            else
            {
             alert("no it's not checked my friend");
            }
        }
   
 <form name="Shahab_Forms">
            <input type="checkbox" name="TheCheckBox"/>
            <input type="button" value="Press Me" onclick="Validator();"/> 
    </form>

答案 1 :(得分:-3)

     function Validator(){
            if(document.shahab_Form.TheCheckBox.checked)
            {
                alert("it's already Checked my Friend!");
            }
            else
            {
             alert("no it's not checked my friend");
            }
        }
    <form name="Shahab_Forms">
            <input type="checkbox" name="TheCheckBox"/>
            <input type="button" value="Press Me" onclick="Validator();"/> 
    </form>