bootstrap:能夠增加兼容性的強(qiáng)大框架.
為阜平等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及阜平網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站設(shè)計、成都做網(wǎng)站、阜平網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
因為項目需要數(shù)據(jù)驗證,看bootstrapValidator 還不錯,就上手一直,完美兼容,話不多說。
bootstrapValidator的github地址
需要引用css:
bootstrap.min.css
bootstrapValidator.min.css
js:
jQuery-1.10.2.min.js
bootstrap.min.js
bootstrapValidator.min.js
以上這些都是必須的。
先上個簡單的例子,只要導(dǎo)入相應(yīng)的文件可以直接運行:
<!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定義好的樣式,驗證是根據(jù)input中的name值 --> <form id="defaultForm" method="post" class="form-horizontal" action="aaa.html"> <!-- 下面這個div必須要有,插件根據(jù)這個進(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)的鍵值對 * */ $('#defaultForm').bootstrapValidator({ message: 'This value is not valid', feedbackIcons: {/*輸入框不同狀態(tài),顯示圖片的樣式*/ valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-refresh' }, fields: {/*驗證*/ username: {/*鍵名username和input name值對應(yīng)*/ 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>
當(dāng)然,以上都是插件寫好的規(guī)則,如果想自己加匹配規(guī)則怎么辦呢?
如下只要在input相對應(yīng)的鍵值中加入一個regexp:{}鍵值對(在上面的js基礎(chǔ)上修改)
username: {/*鍵名和input name值對應(yīng)*/ message: 'The username is not valid', validators: { notEmpty: {/*非空提示*/ message: '用戶名不能為空' }, regexp: {/* 只需加此鍵值對,包含正則表達(dá)式,和提示 */ regexp: /^[a-zA-Z0-9_\.]+$/, message: '只能是數(shù)字和字母_.' }, stringLength: {/*長度提示*/ min: 6, max: 30, message: '用戶名長度必須在6到30之間' }/*最后一個沒有逗號*/ } },
以上所述是小編給大家介紹的BootStrapValidator初使用教程詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對創(chuàng)新互聯(lián)網(wǎng)站的支持!
網(wǎng)頁題目:BootStrapValidator初使用教程詳解
當(dāng)前路徑:http://jinyejixie.com/article30/jjehso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、網(wǎng)站內(nèi)鏈、自適應(yīng)網(wǎng)站、做網(wǎng)站、虛擬主機(jī)、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)