2012-11-24 20 views
0

這是我的表單和jQuery驗證代碼。問題是:它驗證前兩個字段,即標題和desc,但它不會從品種字段驗證。Jquery驗證不適用於某些文本框

<div class='span10 well' style='display:block;'> 
    <h4>Listing Details : <span class='btn btn-info btn- small' style='display:inline;'>Public</span><a href="#" class="tt"><img src='../../img/help.png' class='helpicon' /><span class="tooltip"><span class="top"></span><span class="middle">The information entered here will only shown to all customers who view your profile!</span><span class="bottom"></span></span></a></h4><br> 
    <div class='test span9 well'> 
    <form name='listingForm' id='listingForm' action='processListing.php' method='POST' onsubmit='validateForm()'> 
      <label for "title"> Title: </label> 
        <input class='span8' type='text' name='title' id='title' placeholder='Catchy one-liner title...'> 
        <!-- help message --> 
        <a href="#" class="tt"><img src='../../img/help.png' class='helpicon' /><span class="tooltip"><span class="top"></span><span class="middle">A title is your first impression key! Make it catchy but informative to attract more customers.</span><span class="bottom"></span></span></a> 
      <br><br><label for "desc"> Description: </label> 
        <textarea id="desc" name="desc" class='span8' rows=5 placeholder='Detailed description about your listing...'></textarea> 
        <a href="#" class="tt"><img src='../../img/help.png' class='helpicon' /><span class="tooltip"><span class="top"></span><span class="middle">A detailed description about your listing helps prospective customers know more about you. Talk about your pet, your family, how much you love your pet or an overview about how you can take the best possible care of the customer's four-feeted friend!</span><span class="bottom"></span></span></a> 
    </div> 
    <div class='myspan well'> 
    <label for "breeds"> Breeds: <a href="#" class="tt"><img src='../../img/help.png' class='helpicon' /><span class="tooltip"><span class="top"></span><span class="middle">Key in all the breeds that you are willing to host. The more the merrier, so select as many as you want!</span><span class="bottom"></span></span></a></label> 
      <input type='text' name='breeds' id='breeds' value='' placeholder='Breeds you are willing to take in' onfocus='getDynamicData("Breed",this)'> 

    <br><br><label for "boardingtype"> Accomodation Type: 
    <a href="#" class="tt"><img src='../../img/help.png' class='helpicon' /><span class="tooltip"><span class="top"></span><span class="middle">The type of accomodation that you can provide for the customer's best friend!</span><span class="bottom"></span></span></a> 
    </label> 

      <input type='radio' name='boardingtype' id='Apartment'> Apartment 
      <input type='radio' name='boardingtype' id='House'> House 
      <input type='radio' name='boardingtype' id='Boarding'> Boarding 
    <br><br> 
    <label for "amenities"> Amenities: 
    <a href="#" class="tt"><img src='../../img/help.png' class='helpicon' /><span class="tooltip"><span class="top"></span><span class="middle">Amenities available for a customer's pet. Choose all that apply. If you have more, be sure to mention it in the description of your listing.</span><span class="bottom"></span></span></a> 
    </label> 
      <input type='checkbox' id='amenity1' name="amenity1" value='Y'> <span style='padding-left: 10px'>Proximity to Vet</span> 
      <br><input type='checkbox' id='amenity2' name="amenity2" value='Y'> <span style='padding-left: 10px'>Play Area</span> 
      <br><input type='checkbox' id='amenity3' name="amenity3" value='Y'> <span style='padding-left: 10px'>24x7 Caretaker</span> 
      <br><input type='checkbox' id='amenity4' name="amenity4" value='Y'> <span style='padding-left: 10px'>Toys</span> 
    </div> 

這裏是我的jQuery驗證:

$(document).ready(function(){ 
    $("#listingForm").validate({ 
      rules: { 
       title: "required", 
       desc: "required", 
       breeds: "required", 
       price: { 
        required: true, 
        }, 

      }, 
      messages: { 
       title: "blah blah", 
       desc: "blah blah", 
       breeds: "blah blah", 

       price:"blah blah" 
      } 
     }); 

    }); 
+0

您的驗證規則中出現語法錯誤。刪除「price:{required:true,},」結尾處的逗號 – ffffff01

回答

1

的問題是,其餘字段不是形式的一部分。表單和div必須正確嵌套。您有:

<div class='test span9 well'> 

表格開始之前。與此匹配的</div>也隱含地結束了該表格。如果您想將表單拆分成多個部門,則需要將中的<div>標籤。

您也錯過了span9分部的收盤</form></div>