jQuery의 verify.js 양식 유효성 검사 플러그인을 사용하는 방법(코드 예)

青灯夜游
풀어 주다: 2018-10-23 17:57:09
앞으로
2019명이 탐색했습니다.

본 글의 내용은 jQuery의 verify.js 양식 검증 플러그인(코드 예시) 사용법을 소개하는 것입니다. 도움이 필요한 친구들이 참고할 수 있기를 바랍니다.

효과:

#🎜🎜 #

코드:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>表单验证插件Validate</title>
    <script src="js/jquery-1.10.2.min.js"></script>
    <script src="js/jquery.validate.min.js"></script>
    <style>
        body {
            background-color: #000;
        }
        
        form {
            width: 361px;
            margin: 80px auto;
            padding: 50px;
            border: 2px solid #666;
            box-shadow: 0 0 5px rgba(255, 255, 255, 0.2);
            background-color: #999;
            border-radius: 10px;
            box-sizing: border-box;
        }
        
        form>p {
            margin-bottom: 20px;
            color: #fff;
        }
        
        form>p>label {
            display: inline-block;
            width: 80px;
            text-align: center;
        }
        
        label.error {
            display: block;
            width: 100%;
            color: rgb(189, 42, 42);
            font-size: 12px;
            text-align: right;
            margin-top: 5px;
        }
        
        input {
            width: 170px;
            height: 20px;
            outline: none;
            background-color: #ddd;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        
        .submit {
            width: 170px;
            margin: 30px auto 0;
        }
        
        .submit input {
            background-color: #0099aa;
            color: #fff;
            border: 0;
            padding: 5px;
            height: 30px;
        }
    </style>
</head>

<body>
    <form id="signupForm" action="" method="post">
        <p>
            <label for="name">姓名:</label>
            <input type="text" id="name" name="name">
        </p>
        <p>
            <label for="email">邮箱:</label>
            <input type="email" id="email" name="email">
        </p>
        <p>
            <label for="password">密码:</label>
            <input type="password" id="password" name="password">
        </p>
        <p>
            <label for="confirm_password">确认密码:</label>
            <input type="password" id="confirm_password" name="confirm_password">
        </p>
        <p class="submit">
            <input type="submit" value="提交">
        </p>
    </form>
</body>
<script>
    $(function() {
        $("#signupForm").validate({
            rules: {
                name: "required",
                email: {
                    required: true,
                    email: true
                },
                password: {
                    required: true,
                    minlength: 5
                },
                confirm_password: {
                    required: true,
                    minlength: 5,
                    equalTo: "#password"
                }
            },
            messages: {
                name: "请输入姓名",
                email: {
                    required: "请输入Email地址",
                    email: "请输入正确的Email地址"
                },
                password: {
                    required: "请输入密码",
                    minlength: "密码不能小于5个字符"
                },
                confirm_password: {
                    required: "请输入确认密码",
                    minlength: "确认密码不能小于5个字符",
                    equalTo: "两次输入的密码不一致"
                }
            }
        });
    })
</script>

</html>
로그인 후 복사

위 내용은 jQuery의 verify.js 양식 유효성 검사 플러그인을 사용하는 방법(코드 예)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:cnblogs.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!