2011-04-07 75 views
2

我有复选框的输入型在我的形式,我想使用jQuery验证:http://docs.jquery.com/Plugins/Validation使用jQuery验证检查选中的复选框

我有十几种其他形式的矿井做工精细,但没有这些表单有复选框。我如何检查以确保使用此插件检查复选框?

目前,我有它这样的:当我尝试来验证它

... 
termsConditions: { 
    required: true 
} 
... 

<input type="checkbox" id="termsConditions" name="termsConditions"/> I agree to the <a href="terms">terms and conditions</a> 
<label style="float: none;" for="termsConditions" class="error" generated="true"></label> 

什么也没有发生。任何帮助?

回答

4

使用"required"

$("#signupForm").validate({ 
    rules:{ 
     termsConditions : "required" 
    } 
}); 

或者你也可以在类"required"简单地添加到您的复选框。

<input type="checkbox" id="termsConditions" class="required" name="termsConditions"/> 

Example on jsfiddle

+0

这也是同样的问题。 – AKor 2011-04-07 21:47:00

+0

jsFiddle示例适用于Chrome 10上的我。 – 2011-04-07 21:49:48

+0

@Sennheiser使用''required''或添加类''required''应该可以工作,如果不是请发布更多的html和'.validate()'选项来查看是否其他事情正在引发问题。 – 2011-04-07 21:50:11

0

另一个可能的原因可能是,复选框字段是不可见的。任何隐藏的输入都会跳过验证。

如果您希望验证隐藏字段,您可以将忽略选项设置为ignore: 'hidden'

$('#form').validate({ 
    ignore: [] 
});