我的验证表格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;
答案 0 :(得分:0)
JavaScript是区分大小写的。 Shahab_Forms
与shahab_forms
不同。
您的代码中有2个错误:
1)caseSenstivity,即shahab_Forms
与Shahab_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>