2013-11-22 231 views
0

我開始使用審定的jQuery插件,很不解,爲什麼它不工作,這是我的JavaScript代碼是: 「jQuery驗證不顯示錯誤消息

$(document).ready(function() { 
    $('#shipper_form').validate({ 
     errorLabelContainer: "#errors", 
     rules: { 
      email: { 
       required: true, 
       email: true 
      }, 
      business: "required", 
      address: { 
       required: true, 
      }, 
      zipcode: { 
       required: true, 
      }, 
      phone: { 
       required: true, 
      }, 
      contact_name: { 
       required: true, 
      }, 
     }, 
     messages : { 
      email : "Required Email *", 
      business : "Required Business *", 
      address : "Required Address *", 
      zipcode : "Required Zip Code*", 
      phone : "Required Phone*", 
      contact_name : "Required Contact Name*", 
     }, 
     submitHandler: function (form) { 
      return false; 
     } 
    }); 
}); 
</script>" 

形式:

<div id="errors"></div> 
     <form method="post" action="signup.php"> 
     <table cellspacing="4" cellpadding="4"> 
      <tr> 
       <td> 
        <input type="text" id="email" name="email" style="width: 300px;" class="form-control placeholder" placeholder="Email Address"> 
        <span id="email_success" class="glyphicon glyphicon-check" style="color: green; display: none;"></span> 
       </td> 
      </tr> 
      <tr> 
       <td> 

        <input type="text" id="business" name="business" style="width: 300px;" class="form-control placeholder" placeholder="Business Name or DBA"> 
        <span class="glyphicon glyphicon-check" style="color: green; display: none;"></span> 
       </td> 
      </tr> 
     </table> 
    </form> 

錯誤信息顯示爲電子郵件,但不是業務或任何其他人,我不知道我在做什麼錯。謝謝。

+0

您的'#shipper_form'元素在哪裏?沒有元素具有該ID名稱... – Sergio

+0

對不起,我在表單中忽略了id,即「id = shipper_form」,當我移動它時。 –

+0

請在下面發佈您的解決方案作爲答案。 – Sparky

回答

3

在我的情況下,驗證不是w因爲jquery.validate.js和jquery.validate.unobtrusive.js都被添加到頁面,所以請加我自己。在這種情況下,驗證工作在一半的頁面中,並沒有在另一半工作(通過不工作,我的意思是:表單仍然得到驗證,但沒有顯示錯誤消息。)

刪除jquery.validate .unobtrusive.js從頁面中解決了問題。

相關問題