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

首頁(yè) > 開(kāi)發(fā) > JS > 正文

BootStrapValidator初使用教程詳解

2024-05-06 16:35:07
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

bootstrap:能夠增加兼容性的強(qiáng)大框架.

因?yàn)轫?xiàng)目需要數(shù)據(jù)驗(yàn)證,看bootstrapValidator 還不錯(cuò),就上手一直,完美兼容,話(huà)不多說(shuō)。

bootstrapValidator的github地址

需要引用css:

bootstrap.min.css

bootstrapValidator.min.css

js:

jQuery-1.10.2.min.js

bootstrap.min.js

bootstrapValidator.min.js

以上這些都是必須的。

先上個(gè)簡(jiǎn)單的例子,只要導(dǎo)入相應(yīng)的文件可以直接運(yùn)行:

<!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定義好的樣式,驗(yàn)證是根據(jù)input中的name值 -->  <form id="defaultForm" method="post" class="form-horizontal" action="aaa.html">    <!-- 下面這個(gè)div必須要有,插件根據(jù)這個(gè)進(jìn)行添加提示 -->    <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() {    /**     * 下面是進(jìn)行插件初始化     * 你只需傳入相應(yīng)的鍵值對(duì)     * */    $('#defaultForm').bootstrapValidator({      message: 'This value is not valid',      feedbackIcons: {/*輸入框不同狀態(tài),顯示圖片的樣式*/        valid: 'glyphicon glyphicon-ok',        invalid: 'glyphicon glyphicon-remove',        validating: 'glyphicon glyphicon-refresh'      },      fields: {/*驗(yàn)證*/        username: {/*鍵名username和input name值對(duì)應(yīng)*/          message: 'The username is not valid',          validators: {            notEmpty: {/*非空提示*/              message: '用戶(hù)名不能為空'            },            stringLength: {/*長(zhǎng)度提示*/              min: 6,              max: 30,              message: '用戶(hù)名長(zhǎng)度必須在6到30之間'            }/*最后一個(gè)沒(méi)有逗號(hào)*/          }        },        password: {          message:'密碼無(wú)效',          validators: {            notEmpty: {              message: '密碼不能為空'            },            stringLength: {              min: 6,              max: 30,              message: '用戶(hù)名長(zhǎng)度必須在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>

當(dāng)然,以上都是插件寫(xiě)好的規(guī)則,如果想自己加匹配規(guī)則怎么辦呢?

如下只要在input相對(duì)應(yīng)的鍵值中加入一個(gè)regexp:{}鍵值對(duì)(在上面的js基礎(chǔ)上修改)

username: {/*鍵名和input name值對(duì)應(yīng)*/          message: 'The username is not valid',          validators: {            notEmpty: {/*非空提示*/              message: '用戶(hù)名不能為空'            },            regexp: {/* 只需加此鍵值對(duì),包含正則表達(dá)式,和提示 */              regexp: /^[a-zA-Z0-9_/.]+$/,              message: '只能是數(shù)字和字母_.'            },            stringLength: {/*長(zhǎng)度提示*/              min: 6,              max: 30,              message: '用戶(hù)名長(zhǎng)度必須在6到30之間'            }/*最后一個(gè)沒(méi)有逗號(hào)*/          }        },

以上所述是小編給大家介紹的BootStrapValidator初使用教程詳解,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)VeVb武林網(wǎng)網(wǎng)站的支持!


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到JavaScript/Ajax教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 白玉县| 林周县| 霍林郭勒市| 博兴县| 津南区| 久治县| 麻栗坡县| 余庆县| 宁蒗| 高青县| 绥宁县| 澄江县| 略阳县| 噶尔县| 新化县| 西安市| 长宁县| 三亚市| 顺昌县| 丰宁| 加查县| 绥中县| 花垣县| 曲靖市| 剑河县| 高陵县| 延安市| 恭城| 孙吴县| 曲沃县| 邵阳县| 汤原县| 仙居县| 金堂县| 汝城县| 历史| 扎鲁特旗| 福泉市| 赤壁市| 乐业县| 江北区|