簡體   English   中英

在ruby on rails上使用jQuery驗證提交按鈕不起作用

[英]Submit button not working using jQuery validation in ruby on rails

我正在使用ruby2和rails4。 我使用jQuery進行驗證。 驗證錯誤是正確顯示的,但是當我點擊提交按鈕時,雖然我已經為字段指定了正確的值,但它什么也沒做。 有人可以幫我解決問題嗎? 我的代碼如下所示。 謝謝。

jQuery插件:

http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.js
 http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.min.js

在download.html.erb中

    <%= form_tag file_download_contacts_path, :method => :post, :id => 'contact-form'  do |f| %>         
  <h3><b>Download Form</b></h3>      
  <div>   

  <div><%=  label_tag :Name  %><br />  
    <%= text_field_tag "contact[name]" , nil, placeholder: "Your Name" %></div>         
<div><%=  label_tag :Email %><br />
    <%= email_field_tag "contact[email]" , nil, placeholder: "your@mail.com" %></div>
<div><%=  label_tag :Mobile %><br />
    <%= telephone_field_tag "contact[phone]" , nil, placeholder: "Your Contact No" %></div>
<div><br/><%= button_tag 'submit' %></div>
  </div>    
 <% end %>              


 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js" type="text/javascript"></script>
<script src="/assets/jquery.validate.js"></script>
<script src="/assets/jquery.validate.min.js"></script>   
<script type="text/javascript">
$(document).ready(function () {
$("#contact-form").validate({
debug: true,
rules: {
"contact[name]": {required: true, max: false, min: false},  
"contact[email]": {required: true, email: true},        
"contact[phone]": {required: true, digits: true, minlength: 10, maxlength: 10}                
}
});
});
</script>           

來自jQuery Validation Plugin文檔

debug(默認值:false)

類型:布爾值

啟用調試模式。 如果為true,則表單未提交,並且控制台上會顯示某些錯誤

只需刪除debug: truedebug: true形成您的驗證方法,您就可以了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM