当前位置: 移动技术网 > IT编程>开发语言>JavaScript > cookie的复制与使用记住用户名实现代码

cookie的复制与使用记住用户名实现代码

2018年09月18日  | 移动技术网IT编程  | 我要评论

代码如下:


<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "https://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="scripts/jquery.cookie.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
if ($.cookie("username")) {
$("#user").val($.cookie("username"));

}

$("#login").click(function () {
$.cookie("username", $("#user").val(), { expires: 7 }); //{ expires: 7 }的意思是让cookie保存7天
})
})
</script>
</head>
<body>
<input type="text" id="user" />
<input type="button" id="login" value="提交" />
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网