基于Bootstrap+jQuery.validate实现Form表单验证

基于Bootstrap jQuery.validate Form表单验证实践项目结构 :

github 上源码地址:https://github.com/starzou/front-end-example

1、form 表单代码[html]

代码如下:
Bootstrap Form Template <Meta name="viewport" content="width=device-width,initial-scale=1.0">
dio-inline"> boy
Box">
Box">

需要引用jquery.js,bootstrap.js,jquery.validate.js 库

2、form.js 代码[javascript]

代码如下:
required : true }, password : { required : true }, intro : { required : true } }, messages : { name : { required : "Username is required." }, password : { required : "Password is required." }, intro : { required : "Intro is required." } }, highlight : function(element) { $(element).closest('.form-group').addClass('has-error'); }, success : function(label) { label.closest('.form-group').removeClass('has-error'); label.remove(); }, errorPlacement : function(error,element) { element.parent('div').append(error); }, submitHandler : function(form) { form.submit(); } }); $('.form-horizontal input').keypress(function(e) { if (e.which == 13) { if ($('.form-horizontal').validate().form()) { $('.form-horizontal').submit(); } return false; } }); } return { init : function() { handleSubmit(); } }; }();

效果

相当不错的一个表单验证的特效,这里推荐给大家,小伙伴们自由美化下就可以用到自己项目中了。

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...