我正在尝试使用jQuery插件验证以下表单但尚未成功。请帮我解决这个问题。
<ol>
<li>
<label for="address1" class="biz">Address 1<span class="required">*</span></label>
<input id="address1" name="address[address1]" class="text" type="text" >
</li>
<li>
<label for="address2" class="biz">Address 2</label>
<input id="address2" name="address[address2]" class="text" type="text"/>
</li>
<li>
<label for="city" class="biz">City<span class="required">*</span></label>
<input id="city" name="address[city]" class="text" type="text"/>
</li>
goes on....
rules: {
name: { required: true },
phone: { required: true },
address: { required: true },
}
以上规则不起作用。 提前谢谢你们。
答案 0 :(得分:1)
您需要使用完整的字段名称并引用它们。参考:http://docs.jquery.com/Plugins/Validation/Reference#Fields_with_complex_names_.28brackets.2C_dots.29
$("#form").validate({
rules: {
"address[address1]": { required: true },
"address[address2]": { required: true },
"address[city]": { required: true },
}
});