Cookie copy and use remember the user name implementation code

  • 2020-03-26 23:05:20
  • OfStack

 
<!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> 
<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} means let the cookie last for 7 days
}) 
}) 
</script> 
</head> 
<body> 
<input type="text" id="user" /> 
<input type="button" id="login" value=" submit " /> 
</body> 
</html> 

Related articles: