BoostrapValidator使用方法

今天来介绍一下bootstrapValidator的使用方法。

举个例子介绍一下:

首先建立一个java web工程,工程目录如下:

 

需要导入的文件有bootstrap.css、boostrapValidator.min.css、bootstrap.js、bootstrapValidator.min.js、form.js、jquery.js

接着建立我们的index.jsp,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>bootstrap校验器</title>
<!-- 引入css文件 -->
<style>
.container {
    width: 100%;
}
 
.showDataTable {
    width: 100%;
}
/*表单中日期组件图标样式配覆盖width:auto*/
.date-input-btn {
    height: 35px;
    width: 35px;
}
 
.qyyj {
    width: 450px;
}
 
.qyyj select {
    height: 25px;
    width: 450px;
    color: #626262;
    line-height: 25px;
    /* background-color:#05b570; */
    margin-right: 1px;
    margin: 1px 0px 1px 2px;
    border: 1 solid #A1AAB3;
}
/*设置标题的文字样式*/
.htext {
    font-size: 14px;
    font-weight: bold;
}
 
/*设置分割线的上下间距*/
hr.fenge {
    margin-top: 10px;
    margin-bottom: 10px;
}
 
/*表单中表单组间距*/
.form-group {
    width: 90%;
    margin-bottom: 10px !important;
}
 
.ue-tabs>li>a {
    font-size: 12px;
    padding: 0 25px;
    line-height: 30px;
    color: #3e99ff
}
 
.form-ll {
    margin-bottom: 10px !important;
    width: 800px;
}
 
.form-picture {
    margin-bottom: 10px !important;
    width: 400px;
    height: 400px
}
 
.form-radio {
    margin-bottom: 10px !important;
    width: 850px;
    height: 850px;
}
 
.Validform_checktip {
    font-size: 14px;
}
 
.btn-cckd {
    font-size: 24.5px;
    border: 1px solid #DDDDDD;
}
</style>
<link rel="stylesheet" href="../css/bootstrap.css" />
<link rel="stylesheet" href="../css/bootstrapValidator.min.css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/bootstrap.js"></script>
<script type="text/javascript" src="../js/bootstrapValidator.min.js"></script>
<script type="text/javascript">
    $(function() {
        $('#saveForm').bootstrapValidator({
            // 默认的提示消息
            message : 'This value is not valid',
            // 表单框里右侧的icon
            feedbackIcons : {
                valid : 'glyphicon glyphicon-ok',
                invalid : 'glyphicon glyphicon-remove',
                validating : 'glyphicon glyphicon-refresh'
            },
            fields : {
                email : {
                    trigger : "change",
                    validators : {
                        notEmpty : {
                            message : '邮箱地址不能为空'
                        }
                    }
                }
            }
        });
    });
</script>
</head>
<body>
    <form class="form-horizontal" id="saveForm" name="saveForm"
        onsubmit="return false">
        <table class="showDataTable">
            <tr>
                <td class="TdRight"><label for="exampleInputEmail1">Email
                        address</label></td>
                <td class="TdRight">
                    <div class="form-group">
                        <input type="text" name="email" class="form-control"
                            id="exampleInputEmail1" placeholder="Email">
                    </div>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

 

 代码比较简单,引入一下js和css文件,然后自己在页面上加入一个boostrapValidator进行校验,校验的内容就是下面的邮箱地址的表单,执行的效果如下:

 

这个地方只是举个例子,说明一下boostrapValidator的用法,还用很多的使用方法,可以参考一下https://www.cnblogs.com/smallthen/p/6780274.html这篇博客,或者直接搜一下boostrapValidator的API网站

  

 

posted @   leagueandlegends  阅读(247)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示