NiceDay007
2020-04-22 14:58
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
fieldset{
width: 400px;
border:1px solid pink;
}
</style>
</head>
<body>
<script src="jq-cj/dist/jquery.validate.js"></script>
<script src="https://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
<button id="yjh">点这</button>
<script>
$('#yjh').click(function(){
alert("这个有用");
})
</script>
<script>
$(document).ready(function(){//当页面载入后
$('#demoForm').validate({//以下约定的是name值
rules:{
username:{
required:true,
minlength:2,
maxlength:10
},
password:{
required:true,
minlength:2,
maxlength:16
}
},
messages:{//提示信息
username:{
required:"必须填写用户名",
minlength:"用户名最小为2位",
maxlength:"最大为40位"
},
password:{
required:"必须填写密码",
minlength:"最小为2位",
maxlength:"最大为16位"
}
}
});
});
</script>
<div>
<form id="demoForm">
<fieldset>
<legend>用户登录</legend>
<label for="username">用户名:</label><!-- for的作用:当点击用户名时使鼠标聚焦在输入框 -->
<input type="text" id="username" name="username"><br>
<label for="password">密 码:</label>
<input type="password" id="password" name="password"><br>
<input type="submit" name="" value="登录">
<input type="reset" name="" value="重置">
</fieldset>
</form>
</div>
</body>
</html>
<script src="jq-cj/dist/jquery.validate.js"></script>
<script src="https://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
引用顺序错了,要倒过来,先引用jquery再引用jquery.validate
jQuery插件——Validation Plugin
65871 学习 · 216 问题
相似问题