1

驗證只在jQuery驗證插件必填字段:下面是我的代碼如何只驗證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提交

+0

你可以顯示你的jQuery代碼嗎? 。 –

+0

$( '#profileDetailsPage')驗證({ \t \t \t \t \t \t \t \t \t規則:{ \t \t \t \t \t姓:{要求:真實,純文字:真}, \t \t \t \t \t address1:{required:true,textonly:true} \t \t \t \t \t \t \t \t \t}, \t \t \t \t消息:{ \t \t \t \t \t姓: 「請輸入您的名字」, \t \t \t \t \t地址1: 「請只輸入文字」 \t \t \t \t }, \t \t \t \t submitHandler:function(){} \t \t \t \t}); – Pandu

回答

0

試用address1required標誌設置爲false

$('#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() {} 
}); 
+0

如果這樣做提交表單不驗證,只是返回: ?title =&firstName =&lastName =&houseNo =&postalCode =&address1 =&address2 =&townCity =&country =&mobileNo = – Pandu