<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin:0;
padding: 0;
}
.form{
width: 200px;
margin:150px auto 0;
}
input[type=checkbox]{
cursor: pointer;
}
input[type=button]{
padding: 5px 10px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="form">
<input id='userName' type="text" placeholder='请输入姓名'/><br/>
<input id='userNumber' type="password" placeholder='请输入密码'/><br/>
<input id='rmbPass' type="checkbox"/>记住密码<br/>
<input id="login" type="button" value="登录" />
</div>
<script type='text/javascript' src='js/require.js' data-main='js/main.js'></script>
</body>
</html>
require.config({
paths:{
"jquery":"jquery.min",
"jquery_cookie":"jquery.cookie"
}
})
require(['jquery','jquery_cookie'],function(){
$(document).ready(function(){
if($.cookie('rmbUser')=='true'){
$('#rmbPass').attr('checked',true);
$('#userName').val($.cookie('userName'));
$('#userNumber').val($.cookie('userNumber'));
}
})
$('#login').on('click',function(){
var userName=$('#userName').val();
var userNumber=$('#userNumber').val();
if(document.getElementById('rmbPass').checked){
$.cookie('rmbUser','true',{expires:7});
$.cookie('userName',userName,{expires:7});
$.cookie('userNumber',userNumber,{expires:7});
}else{
$.cookie('rmbUser','false',{expires:-7});
$.cookie('userName','',{expires:-7});
$.cookie('userNumber','',{expires:-7});
}
})
})