类级插件小案例
<!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>Document</title>
</head>
<body>
用户名:<input type="text" class="user"><br> 密码:
<input type="password" class="psd"><br>
<button class="btn">登录</button>
<script src="js/jquery.js"></script>
<script>
$.extend({
isempty: function(u, p) {
return !u || !p ? true : false;
},
check: function(p) {
return p.length > 6 ? true : false;
},
iscorrent: function(p) {
return p !== '123456' ? true : false;
}
})
$('.btn').click(function() {
var user = $('.user').val();
var psd = $('.psd').val();
if ($.isempty(user, psd)) {
alert('内容为空');
} else if ($.check(psd)) {
alert('密码太长');
} else if ($.iscorrent(psd)) {
alert('密码不正确');
} else {
alert('密码正确')
location.href = "home.html";
}
})
</script>
</body>
</html>