美观简洁的bootstrap 表单验证代码

美观简洁的bootstrap 表单验证代码

美观简洁的bootstrap 表单验证代码,如上图所示,点击登录按钮,在输入框下方显示错误提示信息

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8" />
  <title>ipput</title>
  <!-- 新 Bootstrap4 核心 CSS 文件 -->
  <link rel="stylesheet" href="css/bootstrap.min.css">
  <!-- <link rel="stylesheet" href="css/fontawesome.min.css" /> -->
  <!-- 移动优先 -->
  <meta name="viewport" content="width=device-with, initial-scale=1,shrink-to-fit=no" />
 </head>
 <body>
  <div class="container" >
   <form novalidate="" class=" needs-validation">
    <div class="class=" form-group">
     <label>邮箱</label>
     <input type="text" class=" form-control" required />
     <!-- <small class="form-text text-muted">请输入邮箱</samll>-->
     <div class=" invalid-feedback">请输入邮箱!</div>
    </div>
    <div class=" form-group">
     <label class=" ">密码</label>
     <input type="password" class="form-control" required="required" />
     <div class=" invalid-feedback">请输入密码!</div>
    </div>
    <div class="form-check">
     <input type="checkbox" class=" form-check-input" />
     <label class="form-check-label">同意</label>
    </div>
    <button class="btn btn-primary">登录</button>
   </form>
  </div>
  <script>			
   // Example starter JavaScript for disabling form submissions if there are invalid fields
   (function() {
    'use strict';
    window.addEventListener('load', function() {
     // Fetch all the forms we want to apply custom Bootstrap validation styles to
     var forms = document.getElementsByClassName('needs-validation');
     // Loop over them and prevent submission
     var validation = Array.prototype.filter.call(forms, function(form) {
      form.addEventListener('submit', function(event) {
       if (form.checkValidity() === false) {
        event.preventDefault();
        event.stopPropagation();
       }
       form.classList.add('was-validated');
      }, false);
     });
    }, false);
   })();
  </script>
  <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  <script src="./js/jquery.min.js"></script>
  <!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单,包含了 popper.min.js -->
  <script src="js/bootstrap.bundle.min.js"></script>
  <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
  <script src="js/bootstrap.min.js"></script>
 </body>
</html>

125jz网原创文章。发布者:江山如画,转载请注明出处:http://www.125jz.com/4770.html

(0)
江山如画的头像江山如画管理团队
DiskGenius 数据恢复,扩展C盘,分区管理软件-免费下载
上一篇 2020年2月8日 上午10:40
hao123网站给我们的启示-1个网站让初中毕业的我成为千万富翁
下一篇 2020年2月10日 下午9:13

99%的人还看了以下文章

  • CSS 实现水平、垂直居中布局代码大全

    CSS实现水平居中 若是行内元素,则直接给其父元素设置text-align: center即可 若是块级元素,则直接给该元素设置margin: 0 auto即可 若子元素包含浮动元素,则给父元素设置width:fit-content并且配合margin .parent { width: -webkit-fit-content; width: -moz-fit…

    2019年11月26日
    16.3K0
  • 第4课:字体

    这一课,你将学习字体以及如何用CSS来设置字体。我们还会考虑如何解决“网站所选的字体仅当访问者的PC上安装有该字体时才会被显示”这一难题。本课将对下列CSS属性进行讲解: font-family font-style font-variant font-weight font-size font 字体族[font-family] CSS属性font-fami…

    2020年2月22日
    7.9K0
  • 跟永哥学HTML5(3):HTML5新增语义化元素的使用

    上节课我们讲了html5与html4的区别,Html5对语法进行了简化,一个htm5文档结构代码如下: <!doctype html> <html> <head> <meta charset=”utf-8″> <title>无标题文档</title> </head> <…

    2018年1月26日
    16.6K1
  • CSS制作上一页 下一页 页码显示样式

    今天教大家制作页面的上一页 下一页 页码显示样式,效果如图所示。 <!doctype html> <html> <head> <meta charset=”utf-8″> <title>CSS制作上一页 下一页 页码显示样式|www.125jz.com</title> <style…

    2018年7月29日
    6.7K0
  • 巧用边框线实现立体按钮效果(纯CSS)

    本文教你使用CSS制作立体按钮,代码简单。

    2020年2月2日
    9.5K0
  • 太赞了!推荐2个多彩渐变配色网站

    1、根据心情和情绪生成的渐变色 https://gradienmood.posandu.me/ 色彩是拥有情绪的,但是有情绪的色彩有不一定仅仅只有一种颜色。这个名为 Gradien Mood 的渐变色网站会将不同感觉和渐变色搜集起来,其中有的渐变色甚至拥有极为复杂的情绪,而你需要做的,就是输入你想传递的情绪,然后就能搜到相关的情绪和色彩,包括渐变的 CSS …

    2023年1月18日
    7.3K0

发表回复

登录后才能评论