cookie.js插件的案例:
https://github.com/jaywcjlove/cookie.js/blob/master/README.md 文档 api 在这里即可查看用法
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="../js/cookie.js"></script>
</head>
<body>
名字:<input type="text" name="name" id="name" /><br />
密码:<input type="text" name="pass" id="pass" /><br />
<button id="cun">存cookie</button><br />
<button id="huo">获cookie</button><br />
<button id="shan">删cookie</button><br />
</body>
</html>
<script>
function $(id){
return document.getElementById(id);
}
$("cun").onclick=function(){
var uname=$("name").value;
var pass=$("pass").value;
cookie('name',uname,1);
cookie('pass',pass,1);
}
$("huo").onclick=function(){
alert(document.cookie);
}
$("shan").onclick=function(){
cookie.clear()
}
</script>