BootstrapValidator是一款非常好用的表单验证插件,通过友好的错误提示能增加用户体验。
bootstrapvalidator源码下载
既然是表单验证,那我们最常用的就是用户登录界面,下面来看看测试代码:
<!DOCTYPE html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Twitter --> <meta name="twitter:site" content="@themepixels"> <meta name="twitter:creator" content="@themepixels"> <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:title" content="Starlight"> <meta name="twitter:description" content="Premium Quality and Responsive UI for Dashboard."> <meta name="twitter:image" content="http://themepixels.me/starlight/img/starlight-social.png"> <!-- Facebook --> <meta property="og:url" content="http://themepixels.me/starlight"> <meta property="og:title" content="Starlight"> <meta property="og:description" content="Premium Quality and Responsive UI for Dashboard."> <meta property="og:image" content="http://themepixels.me/starlight/img/starlight-social.png"> <meta property="og:image:secure_url" content="http://themepixels.me/starlight/img/starlight-social.png"> <meta property="og:image:type" content="image/png"> <meta property="og:image:width" content="1200"> <meta property="og:image:height" content="600"> <!-- Meta --> <meta name="description" content="Premium Quality and Responsive UI for Dashboard."> <meta name="author" content="ThemePixels"> <title>欢迎使用</title> <!-- vendor css --> <link href="../lib/font-awesome/css/font-awesome.css" rel="stylesheet"> <link href="../lib/Ionicons/css/ionicons.css" rel="stylesheet"> <!-- Starlight CSS --> <link rel="stylesheet" href="../css/starlight.css" > <!-- 将下载好的BootstrapValidator js,css文件导入,配合bootstrap插件使用 --> <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css" /> <link rel="stylesheet" href="../dist/css/bootstrapValidator.css" /> <script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.min.js">下面看看测试效果:
当不输入内容直接提交时,提示不能为空:
当输入字符不符合规定位数时,提示:
可根据需求继续添加表单验证
如果大家还想深入学习,可以点击这里进行学习,再为大家附3个精彩的专题:
Bootstrap学习教程
Bootstrap实战教程
Bootstrap插件使用教程
以上就是关于本文的全部内容,希望对大家的学习有所帮助。