大神们帮我看看代码的问题吧

来源:2-5 基本验证方法(number、digits、equalTo)

慕粉3760367

2016-10-24 14:40

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css" media="screen">
    form{width:300px;}
</style>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>biaodan</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
</head>
<body>
    <form id="demoForm">
    <fieldset> 用户登陆
    <p>
    <label for="username">用户名:</label>
   <input type="text" value="" id="username" name="username">
    </p>
    <p>
    <label for="password">密码:</label>
   <input type="password" value="" id="password" name="password" >
    </p>
     <label for="cpassword">确认密码:</label>
   <input type="password" value="" id="cpassword" name="cpassword" >
    </p>
    <p><input type="submit" value="登陆"></p>
    </fieldset>
   </form>
   <script src="http://cdn.bootcss.com/jquery/2.2.3/jquery.min.js"></script>
<script>
   $(document).ready(function (){
    $("#demoForm").validate({
        rules:{
          username:{
            required:true,
            maxlength:10,
            minlength:2,
          },
          password:{
            required:true,
            maxlength:10,
            minlength:2
          },
          cpassword:{
            equalTo:"#password",
          }
      
        },
        messages:{
           username:{
            required:"必须填写用户名",
            maxlength:"用户名最大为10位",
            minlength:"用户名最小为2位",
          },
          password:{
            required:"必须填写用密码",
            maxlength:"密码最大为10位",
            minlength:"密码最小为2位"
          }
           cpassword:{
            equalTo:"两次输入的密码不一致",
          }
        }

    });
   });
</script>
</body>
</html>

写回答 关注

6回答

  • 慕仰8118372
    2018-05-23 02:08:53

    在你配置之前引入validate.js

  • 慕粉3760367
    2016-10-25 14:37:27

    怎么引入validate插件

    Frank_...

    先引入jQuery链接,在引入validate插件插件: <script src="vendor/jquery-1.10.0.js"></script> <script src="vendor/jquery.validate-1.13.1.js"></script> 前提是你需要下载好validate插件在本地, 下载地址:https://jqueryvalidation.org/

    2016-11-01 16:31:05

    共 1 条回复 >

  • flying_chen
    2016-10-25 11:45:06

    messages上面那个大括符少了','

  • flying_chen
    2016-10-25 11:16:35

    代码中没引入validate插件  

  • 慕粉3760367
    2016-10-25 09:34:15

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <style type="text/css" media="screen">
        form{width:300px;}
    </style>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>biaodan</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <link href="" rel="stylesheet">
    </head>
    <body>
        <form id="demoForm">
        <fieldset> 用户登陆
        <p>
        <label for="username">用户名:</label>
       <input type="text" value="" id="username" name="username">
        </p>
        <p>
        <label for="password">密码:</label>
       <input type="password" value="" id="password" name="password" >
        </p>
         <label for="cpassword">确认密码:</label>
       <input type="password" value="" id="cpassword" name="cpassword" >
        </p>
        <p><input type="submit" value="登陆"></p>
        </fieldset>
       </form>
       <script src="http://cdn.bootcss.com/jquery/2.2.3/jquery.min.js"></script>
    <script>
       $(document).ready(function (){
        $("#demoForm").validate({
            rules:{
              username:{
                required:true,
                maxlength:10,
                minlength:2,
              },
              password:{
                required:true,
                maxlength:10,
                minlength:2,
              },
              cpassword:{
                equalTo:"#password",
              },
          
            }
            messages:{
               username:{
                required:"必须填写用户名",
                maxlength:"用户名最大为10位",
                minlength:"用户名最小为2位",
              },
              password:{
                required:"必须填写用密码",
                maxlength:"密码最大为10位",
                minlength:"密码最小为2位"
              },
               cpassword:{
                equalTo:"两次输入的密码不一致",
              },
            },

        });
       });
    </script>
    </body>
    </html>

    怎么还是不行

  • xlhy_
    2016-10-24 15:32:12

    还是那个问题,你没引入validate,还有就是对象的属性之间要用‘,’分隔,你配置项messages的后两个属性之间少了‘,’
    http://img.mukewang.com/580db8740001c0e303600180.jpg

jQuery插件——Validation Plugin

validation让客户端表单验证变容易,缩短用户等待时间

65871 学习 · 216 问题

查看课程

相似问题