Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
    <meta charset="utf-8">
    <title>jqTreeGrid</title>
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<style>
.row {
    margin: 0
}

body {
    padding: 1rem;
}

.error {
    color: red;
}
</style>

<body>
    <form class="form">
        <div class="form-group">
            <label>用户名</label>
            <input type="text" class="form-control" name="userName" placeholder="用户名">
        </div>
        <div class="form-group">
            <label>密码</label>
            <input type="password" class="form-control" name="password" placeholder="密码">
        </div>
        <div class="form-group">
            <label>确认密码</label>
            <input type="password" class="form-control" name="confirm_password" placeholder="请再次输入密码">
        </div>
        <div class="form-group">
            <label>手机号</label>
            <input type="text" class="form-control" name="phone" placeholder="手机号">
        </div>
        <div class="form-group">
            <label>邮箱</label>
            <input type="text" class="form-control" name="email" placeholder="邮箱">
        </div>
        <div class="form-group">
            <label>地址</label>
            <select class="form-control" name="address">
                <option value="">- 请选择 -</option>
                <option value="1">福州</option>
                <option value="2">厦门</option>
                <option value="3">龙岩</option>
            </select>
        </div>
        <div class="form-group">
            <label>爱好</label>
            <div class="form-check form-check-inline">
                <input class="form-check-input" type="checkbox" name="hobby" value="1">
                <label class="form-check-label">游泳</label>
            </div>
            <div class="form-check form-check-inline">
                <input class="form-check-input" type="checkbox" name="hobby" value="2">
                <label class="form-check-label">唱歌</label>
            </div>
            <div class="form-check form-check-inline">
                <input class="form-check-input" type="checkbox" name="hobby" value="3">
                <label class="form-check-label">睡觉</label>
            </div>
        </div>
        <div class="form-group">
            <label>性别</label>
            <div class="form-check form-check-inline">
                <input class="form-check-input" type="radio" name="sex" value="1">
                <label class="form-check-label">男</label>
            </div>
            <div class="form-check form-check-inline">
                <input class="form-check-input" type="radio" name="sex" value="2">
                <label class="form-check-label">女</label>
            </div>
        </div>
        <div class="form-group">
            <label>上传图片</label>
            <input type="file" class="form-control-file" name="file">
        </div>
        <div class="form-group">
            <div class="form-check form-check-inline">
                <input type="checkbox" class="form-check-input" name="subscribe">
                <label class="form-check-label">订阅</label>
            </div>
        </div>
        <div class="form-group">
            <label>订阅方式</label>
            <div class="form-check form-check-inline">
                <input class="form-check-input" type="radio" name="stype" value="1">
                <label class="form-check-label">RSS</label>
            </div>
            <div class="form-check form-check-inline">
                <input class="form-check-input" type="radio" name="stype" value="2">
                <label class="form-check-label">邮箱订阅</label>
            </div>
        </div>
    </form>
    <button id="submit" class="btn btn-primary">Submit</button>
    <button id="reset" class="btn btn-danger">Reset</button>
</body>
<!-- jQuery -->
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min.js"></script>
<!-- popper -->
<script src="https://cdn.bootcss.com/popper.js/1.12.9/umd/popper.min.js"></script>
<!-- bootstrap -->
<script src="https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<!-- jquery-validate -->
<script src="https://cdn.bootcss.com/jquery-validate/1.17.0/jquery.validate.js"></script>
<script src="https://cdn.bootcss.com/jquery-validate/1.17.0/additional-methods.js"></script>
<script src="https://cdn.bootcss.com/jquery-validate/1.17.0/localization/messages_zh.js"></script>
<script>
jQuery.validator.addMethod("checkPhone", function(value, element, params) {
    var checkPhone = /^0?(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57])[0-9]{8}$/;
    return this.optional(element) || (checkPhone.test(value));
}, "请输入正确的手机号");

$(function() {
    validateRule();
    $("#submit").on('click', function() {
        var validator = $(".form").validate();
        var flag = validator.form();
        if (flag) {
            alert("true");
        } else {
            alert("false");
        }
    });
    $("#reset").on('click', function() {
        var validator = $(".form").validate();
        validator.resetForm();
    });
});

function validateRule() {
    $(".form").validate({
        rules: {
            userName: {
                required: true,
                minlength: 3,
                maxlength: 10
            },
            password: {
                required: true,
                minlength: 5
            },
            confirm_password: {
                required: true,
                minlength: 5,
                equalTo: "[name='password']"
            },
            address: {
                required: true
            },
            phone: {
                checkPhone: true
            },
            email: {
                required: true,
                email: true
            },
            hobby: {
                required: true,
                minlength: 2
            },
            sex: {
                required: true
            },
            file: {
                required: true,
                accept: "image/jpg,image/jpeg,image/png,image/gif"
            },
            stype: {
                required: "[name='subscribe']:checked"
            }
        },
        messages: {
            userName: {
                required: "请输入用户名",
                minlength: "用户名长度不能少于{0}个字符",
                maxlength: "用户名长度不能超过{0}个字符"
            },
            password: {
                required: "请输入密码",
                minlength: "密码长度不能小于{0}个字母"
            },
            confirm_password: {
                required: "请输入密码",
                minlength: "密码长度不能小于{0}个字母",
                equalTo: "两次密码输入不一致"
            },
            address: {
                required: "请选择地址"
            },
            email: {
                required: "请输入邮箱",
                email: "邮箱格式不正确"
            },
            hobby: {
                required: "请选择爱好",
                minlength: "至少选择{0}项爱好"
            },
            sex: {
                required: "请选择性别"
            },
            file: {
                required: "请上传附件",
                accept: "只支持jpg,jpeg,png或gif后缀的图片"
            },
            stype: {
                required: "请选择订阅方式"
            }
        },
        errorPlacement: function(error, element) { //指定错误信息位置
            if (element.is(':radio') || element.is(':checkbox')) { //如果是radio或checkbox
                var eid = element.attr('name'); //获取元素的name属性
                error.appendTo(element.parent().parent()); //将错误信息添加当前元素的父元素的父元素后面
            } else {
                error.insertAfter(element);
            }
        }
    });
}
</script>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console