问答详情
源自:1-2 如何开始及举例

想不通,我和老师代码一样的,为什么不能出现提示信息

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link href="type.css" rel="stylesheet" type="text/css">
<script  src="vendor/jquery.validate-1.13.1.js" type="text/javascript"></script>
<script src="vendor/jquery-1.10.0.js" type="text/javascript"></script>
</head>
<body>
<form id="demoForm" method='post'>
<fieldset>
<legend>用户登录</legend>
<p>
<label for="username">用户名</label>
<input type="text" id="username" name="username">
</p>
<p>
<label for="password">密码</label>
<input type="password" id="password" name="password">
</p>
<p>
<input type="submit" value="登录">
</p>
</fieldset>
</form>


<script type="text/javascript">
$(document).ready(function(){
$("#demoForm").validate({
rules: {
username:{
required:true,
minlength:2,
maxlength:10
},
password:{
required:true,
minlength:2,
maxlength:16
}
}
messages: {
username:{
required:"用户名必须填写",
minlength:"用户名最少为2字符",
maxlength:"用户名最大为10字符"
},
password:{
required:"密码必须填写",
minlength:"密码最少为2字符",
maxlength:"密码最大为16字符"
}
}
});
});
</script>
</body>
</html>

为什么我不能产生提示信息呢

CSS样式表

body {

    font-size: 36px;

    line-height: 1.6;

}



p {

    margin: 10px 0;

}



label {

    display: inline-block;

    min-width: 140px;

}



label.error {

    margin-left: 10px;

    color: red;

}



input, button {

    font-size: 36px;

    line-height: 35px;

    border: 1px solid #999;

    min-width: 180px;

}



input.error {

    border: 1px solid red;

}



input[type=submit], button {

    margin-top: 20px;

    font-size: 36px;

    padding: 10px 0;

}

/* CSS Document */




提问者:sunfeisunfei 2015-11-07 15:00

个回答

  • 李晓健
    2015-11-07 20:28:48

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
        <title>无标题文档</title>
        <style>
            body {
                font-size: 36px;
                line-height: 1.6;
            }
    
    
            p {
                margin: 10px 0;
            }
    
    
            label {
                display: inline-block;
                min-width: 140px;
            }
    
    
            label.error {
                margin-left: 10px;
                color: red;
            }
    
    
            input, button {
                font-size: 36px;
                line-height: 35px;
                border: 1px solid #999;
                min-width: 180px;
            }
    
    
            input.error {
                border: 1px solid red;
            }
    
    
            input[type=submit], button {
                margin-top: 20px;
                font-size: 36px;
                padding: 10px 0;
            }
        </style>
        <script src="http://cdn.bootcss.com/jquery/1.10.0/jquery.js"></script>
        <script  src="http://cdn.bootcss.com/jquery-validate/1.13.1/jquery.validate.js" type="text/javascript"></script>
    </head>
    <body>
    <form id="demoForm" method='post'>
        <fieldset>
            <legend>用户登录</legend>
            <p>
                <label for="username">用户名</label>
                <input type="text" id="username" name="username">
            </p>
            <p>
                <label for="password">密码</label>
                <input type="password" id="password" name="password">
            </p>
            <p>
                <input type="submit" value="登录">
            </p>
        </fieldset>
    </form>
    
    
    <script type="text/javascript">
        $(document).ready(function(){
            $("#demoForm").validate({
                rules: {
                    username:{
                        required:true,
                        minlength:2,
                        maxlength:10
                    },
                    password:{
                        required:true,
                        minlength:2,
                        maxlength:16
                    }
                },
                messages: {
                    username:{
                        required:"用户名必须填写",
                        minlength:"用户名最少为2字符",
                        maxlength:"用户名最大为10字符"
                    },
                    password:{
                        required:"密码必须填写",
                        minlength:"密码最少为2字符",
                        maxlength:"密码最大为16字符"
                    }
                }
            });
        });
    </script>
    </body>
    </html>

    两个问题,1 应该先旨入jquery文件 后引入jquery-validate文件,因为jquery-validate对jquery有依赖。

    2.第85(我的代码85行)行少一个,