gpt4 book ai didi

jquery - 客户端验证 jquery 插件不起作用

转载 作者:行者123 更新时间:2023-12-01 04:57:15 25 4
gpt4 key购买 nike

我使用路径 asset\javascripts\jquery.validate.js (rails 3.2) 上的 jquery 插件进行客户端验证。但这不起作用。我的表格:

update_name_phone_city_user_registration_path, :html => { :id => "form_edit_name", :method => :put }, :remote => true) 做 |f| %>


10%> “提交”%>

我的application.js文件:

//= require jquery
//= require jquery_ujs
//= require bootstrap-modal
//= require_tree .


$(document).ready(function() {

$("#form_edit_name").validate({
debug: true,
rules: {
"user[name]": {
required: true,
minlength: 2
},
"user[name]": {
required: 'Your username is required',
minlength: 'The minimum number of characters is 2'
}

alert("ok");
});

});

出了什么问题?

UPD 1 生成的 HTML 代码

<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-modal.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.validate.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>


<form accept-charset="UTF-8" action="/users" class="edit_user" id="form_edit_name" method="post">
<div><label for="user_name">Name</label><br />
<input id="user_name" name="user[name]" size="30" type="text" value="" /></div>
</form>

最佳答案

假设您正在验证这样的测试输入

<input type="text" id="name" name="name" />

试试这个

$("#form_edit_name").validate({
debug: true,
rules: {
"name": { required: true, minlength: 2 },
messages: {
"name": {
required: 'Your username is required',
minlength: 'The minimum number of characters is 2'
}
}
});

关于jquery - 客户端验证 jquery 插件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13562196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com