国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

BootStrapValidator初使用教程詳解

2019-11-19 17:38:30
字體:
來源:轉載
供稿:網友

bootstrap:能夠增加兼容性的強大框架.

因為項目需要數據驗證,看bootstrapValidator 還不錯,就上手一直,完美兼容,話不多說。

bootstrapValidator的github地址

需要引用css:

bootstrap.min.css

bootstrapValidator.min.css

js:

jQuery-1.10.2.min.js

bootstrap.min.js

bootstrapValidator.min.js

以上這些都是必須的。

先上個簡單的例子,只要導入相應的文件可以直接運行:

<!DOCTYPE html><html><head>  <title>Using Ajax to submit data</title>  <link rel="stylesheet" href="css/bootstrap.css" rel="external nofollow" />  <link rel="stylesheet" href="css/bootstrapValidator.css" rel="external nofollow" />  <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>  <script type="text/javascript" src="js/bootstrap.min.js"></script>  <script type="text/javascript" src="js/bootstrapValidator.js"></script></head><body><div class="container">  <!-- class都是bootstrap定義好的樣式,驗證是根據input中的name值 -->  <form id="defaultForm" method="post" class="form-horizontal" action="aaa.html">    <!-- 下面這個div必須要有,插件根據這個進行添加提示 -->    <div class="form-group">      <label class="col-lg-3 control-label">Username</label>      <div class="col-lg-5">        <input type="text" class="form-control" name="username" />      </div>    </div>    <div class="form-group">      <label class="col-lg-3 control-label">Email address</label>      <div class="col-lg-5">        <input type="text" class="form-control" name="email" />      </div>    </div>    <div class="form-group">      <label class="col-lg-3 control-label">Password</label>      <div class="col-lg-5">        <input type="password" class="form-control" name="password" />      </div>    </div>    <div class="form-group">      <div class="col-lg-9 col-lg-offset-3">        <button type="submit" class="btn btn-primary">Sign up</button>      </div>    </div>  </form></div><script type="text/javascript">  $(document).ready(function() {    /**     * 下面是進行插件初始化     * 你只需傳入相應的鍵值對     * */    $('#defaultForm').bootstrapValidator({      message: 'This value is not valid',      feedbackIcons: {/*輸入框不同狀態,顯示圖片的樣式*/        valid: 'glyphicon glyphicon-ok',        invalid: 'glyphicon glyphicon-remove',        validating: 'glyphicon glyphicon-refresh'      },      fields: {/*驗證*/        username: {/*鍵名username和input name值對應*/          message: 'The username is not valid',          validators: {            notEmpty: {/*非空提示*/              message: '用戶名不能為空'            },            stringLength: {/*長度提示*/              min: 6,              max: 30,              message: '用戶名長度必須在6到30之間'            }/*最后一個沒有逗號*/          }        },        password: {          message:'密碼無效',          validators: {            notEmpty: {              message: '密碼不能為空'            },            stringLength: {              min: 6,              max: 30,              message: '用戶名長度必須在6到30之間'            }          }        },        email: {          validators: {            notEmpty: {              message: 'The email address is required and can/'t be empty'            },            emailAddress: {              message: 'The input is not a valid email address'            }          }        }      }    });  });</script></body></html>

當然,以上都是插件寫好的規則,如果想自己加匹配規則怎么辦呢?

如下只要在input相對應的鍵值中加入一個regexp:{}鍵值對(在上面的js基礎上修改)

username: {/*鍵名和input name值對應*/          message: 'The username is not valid',          validators: {            notEmpty: {/*非空提示*/              message: '用戶名不能為空'            },            regexp: {/* 只需加此鍵值對,包含正則表達式,和提示 */              regexp: /^[a-zA-Z0-9_/.]+$/,              message: '只能是數字和字母_.'            },            stringLength: {/*長度提示*/              min: 6,              max: 30,              message: '用戶名長度必須在6到30之間'            }/*最后一個沒有逗號*/          }        },

以上所述是小編給大家介紹的BootStrapValidator初使用教程詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 佛坪县| 闽清县| 灌阳县| 抚顺县| 沛县| 团风县| 马公市| 从江县| 淮滨县| 镇原县| 穆棱市| 泌阳县| 浦江县| 衡南县| 哈巴河县| 扶沟县| 利津县| 寻乌县| 闸北区| 明星| 浪卡子县| 大悟县| 获嘉县| 垦利县| 海盐县| 延安市| 彭山县| 锡林郭勒盟| 柞水县| 鞍山市| 北宁市| 嘉义县| 鹿泉市| 元氏县| 大足县| 磐安县| 扎囊县| 宁化县| 旺苍县| 当雄县| 嘉定区|