在RubyonRails中使用jQuery验证提交按钮不起作用
我正在使用ruby2和rails4。我使用jQuery进行了验证。验证错误显示正确,但当我单击submit按钮时,尽管我为字段指定了正确的值,但它不会执行任何操作。有谁能帮我解决这个问题吗?我的代码如下所示。多谢各位 jQuery插件:在RubyonRails中使用jQuery验证提交按钮不起作用,jquery,ruby-on-rails,ajax,validation,ruby-on-rails-4,Jquery,Ruby On Rails,Ajax,Validation,Ruby On Rails 4,我正在使用ruby2和rails4。我使用jQuery进行了验证。验证错误显示正确,但当我单击submit按钮时,尽管我为字段指定了正确的值,但它不会执行任何操作。有谁能帮我解决这个问题吗?我的代码如下所示。多谢各位 jQuery插件: http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.js http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jqu
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>
:post,:id=>“联系方式”do | f |%>
下载表格
$(文档).ready(函数(){
$(“#联系方式”)。验证({
是的,
规则:{
“联系人[姓名]:{required:true,max:false,min:false},
“联系人[电子邮件]:{required:true,email:true},
“联系人[电话]:{required:true,digits:true,minlength:10,maxlength:10}
}
});
});
来自jQuery验证插件文档
调试(默认值:false)
类型:布尔型
启用调试模式。如果为true,则不提交表单,并且控制台上会显示某些错误
只需删除验证方法中的行
debug:true
,您就可以了。我在同一个注册表单上有3个不同的页面,我想在“下一页”按钮上继续验证(用于转到下一页)。但如果我删除了debug:true
,那么它将无法工作,因为表单将在“下一步”按钮上提交。