jquery表单验证的问题
liuyunlonglong_33
2011-06-03
我在使用jquery进行表单验证时,导入了jquery.js和jquery.validate.js,不知道为什么,即使表单的某项为空,也不进行验证、、、请教!
|
|
陈志霞1206
2011-06-03
建议把code贴出来,大家才能帮忙看看阿
|
|
liuyunlonglong_33
2011-06-03
<script src="js/jquery.validate.js" type="text/javascript"></script> <script src="js/jquery.js" type="text/javascript"></script> <SCRIPT type="text/javascript"> $(document).ready(function(){ $("#signupForm").validate({ rules: { uname: "required", email: { required: true, email: true }, pwd: { required: true, minlength: 5 }, con-pwd:{ required: true, minlength: 5, equalTo: "#pwd" } }, messages: { uname: "请输入姓名", email: { required: "请输入Email地址", email: "请输入正确的email地址" }, pwd: { required: "请输入密码", minlength: jQuery.format("密码不能小于{0}个字符") }, con-pwd: { required: "请输入确认密码", minlength: "确认密码不能小于5个字符", equalTo: "两次输入密码不一致不一致" } } }); }); </SCRIPT> <form id="signupForm" method="post" action=""> <p> <label for="uname"> 用户名: </label> <input id="uname" type="text" name="uname" /> </p> <p> <span style="width: 18px;"></span> <label for="pwd"> 密码: </label> <input type="password" id="pwd" name="pwd" /> </p> <p> <label for="con-pwd"> 确认密码: </label> <input type="password" id="con-pwd" name="con-pwd" /> <span style="width: 20px"></span> </p> <p> <span style="width: 20px"></span> <label for="email"> 邮箱: </label> <input type="text" id="email" name="email" /> </p> <p> <input class="submit" type="submit" value="注册"> <input type="reset" value="取消" /> </p> </form> |
|
yatou_0209
2011-06-13
不是有现成的messages的js吗?你为什么要自己写呢?
|
|
liuyunlonglong_33
2011-06-13
这个知道,但是按照自己的错误提示信息写,也可以呀、、
|
|
jn615
2011-06-13
<script src="js/jquery.validate.js" type="text/javascript"></script>
<script src="js/jquery.js" type="text/javascript"></script> 颠倒下试试 |
|
yatou_0209
2011-06-14
声明的id时不可以用中线呀。你自己用firebug看一下,应该就能看见问题在哪了。
|
|
yutian2211
2011-06-14
yatou_0209 写道 声明的id时不可以用中线呀。你自己用firebug看一下,应该就能看见问题在哪了。
正解 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <script src="http://code.jquery.com/jquery-latest.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.min.js" type="text/javascript"></script> </head> <body> <SCRIPT type="text/javascript"> $(document).ready(function(){ $("#signupForm").validate({ rules: { uname: "required", email: { required: true, email: true }, pwd: { required: true, minlength: 5 }, conpwd:{ required: true, minlength: 5, equalTo: "#pwd" } }, messages: { uname: "请输入姓名", email: { required: "请输入Email地址", email: "请输入正确的email地址" }, pwd: { required: "请输入密码", minlength: jQuery.format("密码不能小于{0}个字符") }, conpwd: { required: "请输入确认密码", minlength: "确认密码不能小于5个字符", equalTo: "两次输入密码不一致不一致" } } }); }); </SCRIPT> <form id="signupForm" method="post" action=""> <p> <label for="uname"> 用户名: </label> <input id="uname" type="text" name="uname" /> </p> <p> <span style="width: 18px;"></span> <label for="pwd"> 密码: </label> <input type="password" id="pwd" name="pwd" /> </p> <p> <label for="con-pwd"> 确认密码: </label> <input type="password" id="conpwd" name="conpwd" /> <span style="width: 20px"></span> </p> <p> <span style="width: 20px"></span> <label for="email"> 邮箱: </label> <input type="text" id="email" name="email" /> </p> <p> <input class="submit" type="submit" value="注册"> <input type="reset" value="取消" /> </p> </form> </body> </html> |
|
zxl10059
2011-06-14
jn615 写道 <script src="js/jquery.validate.js" type="text/javascript"></script>
<script src="js/jquery.js" type="text/javascript"></script> 颠倒下试试 嗯,我也出现过这个问题,应该是js加载顺序的问题,比如你先加载个jquery分页插件,再加载jquery,分页就不能使用了 |
|
mengqingfei
2011-06-15
建议把那两个js文件改成网上的,不要用本地的
|