仅验证jQuery验证插件中的必填字段:以下是我的代码

<label for="firstName">First Name<span class="required">*</span></label>
<input type="text" id="firstName" class="form-control" placeholder="First Name" name="firstName">
<label for="address1">Address Line 1</label>
<input type="text" id="address1" class="form-control" placeholder="Address Line 1" name="address1">


我想跳过表单提交中的地址1

最佳答案

尝试将requiredfalse标志设置为address1

$('#profileDetailsPage').validate({
    rules: {
        firstName:{
            required: true,
            textonly: true
        },
        address1:{
            required: false, // don't require this field
            textonly: true
        }
    },
    messages: {
        firstname: "Please enter your first name",
        address1: "Please enter only text"
    },
    submitHandler: function() {}
});

09-28 05:34