zoukankan      html  css  js  c++  java
  • 使用:valid和:invalid校验表单

    <div class="bruce flex-ct-x">
        <form class="form-validation">
            <div>
                <label>名字</label>
                <input type="text" placeholder="请输入你的名字(1到10个中文)" pattern="^[u4e00-u9fa5]{1,10}$" required>
            </div>
            <div>
                <label>手机</label>
                <input type="text" placeholder="请输入你的手机" pattern="^1[3456789]d{9}$" required>
            </div>
            <div>
                <label>简介</label>
                <textarea required></textarea>
            </div>
        </form>
    </div>

    css:

    .form-validation {
        width: 500px;
        div {
            margin-top: 10px;
            &:first-child {
                margin-top: 0;
            }
        }
        label {
            display: block;
            padding-bottom: 5px;
            font-weight: bold;
            font-size: 16px;
        }
        input,
        textarea {
            display: block;
            padding: 0 20px;
            outline: none;
            border: 1px solid #ccc;
            width: 100%;
            height: 40px;
            caret-color: $blue;
            transition: all 300ms;
            &:valid {
                border-color: $green;
                box-shadow: inset 5px 0 0 $green;
            }
            &:invalid {
                border-color: $red;
                box-shadow: inset 5px 0 0 $red;
            }
        }
        textarea {
            height: 122px;
            resize: none;
            line-height: 30px;
            font-size: 16px;
        }
    }

    效果:

  • 相关阅读:
    14、迭代器协议、生成器、装饰器
    13、文件处理
    12、内置函数
    11、函数(def)
    10、基本数据类型(set)
    9、循环语句
    8、基本数据类型(dict)
    7、基本数据类型(tuple)
    6、基本数据类型(list)
    5、基本数据类型(str)
  • 原文地址:https://www.cnblogs.com/chao202426/p/11489950.html
Copyright © 2011-2022 走看看