-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
139 lines (122 loc) · 4.26 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/jquery-1.12.3.js"></script>
<script src="js/jquery.cookie.js"></script>
<style>
</style>
</head>
<body>
<!-- <div id="div">
<span id="goodId1">商品一</span>
<span>1RMB</span>
<a class="addToCar" href="##">加入购物车</a>
</div>
<div>
<span id="goodId2">商品二</span>
<span>2RMB</span>
<a class="addToCar" href="##">加入购物车</a>
</div>
<div>
<span id="goodId3">商品三</span>
<span>3RMB</span>
<a class="addToCar" href="##">加入购物车</a>
</div>
<button id='jieSuan'>结算</button>
<button id='clearCarts'>清除</button> -->
<script type="text/javascript">
// $.cookie(key, val, {expires: 7, path: "/"});//设置、读取、删除
// var userInfo = {};
// userInfo.userName = "张三";
// userInfo.email = "[email protected]";
// $.cookie("userInfo", JSON.stringify(userInfo), {expires: 7, path: "/"});
// console.log(JSON.parse($.cookie("userInfo")));
// var userInfoCookie = JSON.parse($.cookie("userInfo"));
// userInfoCookie.userName = "李四";
// $.cookie("userInfo", JSON.stringify(userInfoCookie), {expires: 7, path: "/"});
// console.log(JSON.parse($.cookie("userInfo")));
// $.cookie("userName", "lisi", {expires: 7, path: "/"});
// console.log($.cookie("userName"));
// $.cookie(key, val, {expires: 过期时间, path: "路径一般为/"});
// 获取
//$.cookie(key)读取cookie名为key的值
// 增加、修改、删除
//$.cookie(key, val, {expires: 过期时间, path: "路径一般为/"})
// 增加(中文自动编码)
// $.cookie("userName", "zhangsan", {expires: 7, path: "/"});
// $.cookie("userName", "张三", {expires: 7, path: "/"});
// var userInfo = {};
// userInfo.userName = "zhangsan";
// userInfo.email = "[email protected]";
// $.cookie("userInfo", JSON.stringify(userInfo), {expires: 7, path: "/"});
// var goods = {};
// var g0 = "g0"
// goods[g0] = {
// id: "3",
// price: "159rmb",
// num: "5"
// }
// goods["g1"] = {
// id: "1",
// price: "159rmb",
// num: "3"
// }
// $.cookie("carts", JSON.stringify(goods), {expires: 7, path: "/"})
// var goods = JSON.parse($.cookie("carts"));
// // for(var i in goods) {
// // console.log(goods[i].price)
// // }
// var goodId = "g1";
// goods[goodId].price = "300000000rmb";
// $.cookie("carts", JSON.stringify(goods), {expires: 7, path: "/"})
// var goods = JSON.parse($.cookie("carts"));
// for(var i in goods) {
// console.log(goods[i].price)
// }
// 获取
// console.log($.cookie("userName"))
// 修改(key值相同)
// $.cookie("userName", "lisi", {expires: 7, path: "/"});
// 删除
// $.cookie("userName", "", {expires: -1, path: "/"});
// json格式存储value值
// JSON.parse("字符串")将json格式字符串转为json
// JSON.stringfy(json)将json转为json字符串
// 购物车格式
// $.cookie("carts", "{'g0':{'goodId': 1, 'goodName': '女装一', 'goodPrice': '180rmb', 'goodImg': '../img/1.jpg'},'g1':{'goodId': 1, 'goodName': '女装一', 'goodPrice': '180rmb', 'goodImg': '../img/1.jpg'}}", {expires: 7, path: "/"});
//添加到购物车
// $('.addToCar').click(function(){
// var spans = $(this).siblings();
// var goodId = $(spans[0]).attr('id');
// var goodName = $(spans[0]).text();
// var goodPrice = $(spans[1]).text();
// //判断购物车是否有商品
// var goods = $.cookie('carts') ? JSON.parse($.cookie('carts')) : {};
// if(goodId in goods){
// goods[goodId].num++;
// } else {
// goods[goodId] = {
// id : goodId,
// name : goodName,
// price : goodPrice,
// num : 1
// }
// }
// $.cookie("carts", JSON.stringify(goods), {expires:7,path:'/'});
// console.log($.cookie("carts"))
// });
// //结算
// $('#jieSuan').click(function(){
// location.href = "buy.html";
// })
// // 删除
// $("#clearCarts").click(function() {
// $.cookie("carts", "", {expires: -1, path: '/'});
// });
</script>
<input type="radio" name="sex" id="a"><label for="a">男</label>
<input type="radio" name="sex" id="b"><label for="b">男</label>
</body>
</html>