您的位置:首页 > Web前端 > JQuery

通过jquery.cookie.js实现记住用户名和密码的功能

2014-06-23 16:31 1021 查看
<!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=UTF-8" />
<script src="jquery1-11.js"></script>
<script src="jquery.cookie.js"></script>
<script>
$(document).ready(function(){
if($.cookie("userName")){
alert('填充cookie');
$('.userName').val($.cookie("userName"));
$('.pwd').val($.cookie("pwd"));
}
$('button').click(function(){
var userName=$('.userName').val();
var pwd=$('.pwd').val();
$.cookie("userName",userName,{expires:7});
//                保存七天
$.cookie('pwd',pwd,{expires:7});
alert('成功胜出cookie,下次进网页自动填充');
})
})
</script>

</head>
<body>
<input type="text" class="userName"/><br/><br/>
<input type="password" class="pwd"/><br/><br/>
<button >登录</button>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  html javascript