JS+COOKIE购物车
来源:互联网 发布:分布估计算法代码 编辑:程序博客网 时间:2024/04/29 13:35
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Shopping.aspx.cs" Inherits="Shopping" %>
<!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 runat="server">
<title></title>
<script type="text/javascript">
</script>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table class="style1">
<tr>
<td>
<asp:Image ID="Image1" runat="server" Height="226px" ImageUrl="~/001.jpg"
Width="446px" />
</td>
<td>
<asp:Image ID="Image2" runat="server" Height="226px"
ImageUrl="~/766761_111649063996_2.jpg" Width="446px" />
</td>
</tr>
<tr>
<td style="text-align: center">
<a href="buy.aspx?id=产品1" style="text-align: center">去购物</a></td>
<td style="text-align: center">
<a href="buy.aspx?id=产品2">去购物</a></td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="buy.aspx.cs" Inherits="buy" %>
<!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 runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 514px;
}
</style>
<script type="text/javascript">
// function seekcart() {
// if (document.cookie.length > 0) {
// var name = document.getElementById("disp").innerHTML;
// if (document.cookie.search(name) >= 0) { //判断是否记录存在
// var cook = document.cookie;
// var product = cook.split('|'); //分成单记录
// var newproduct = ""; //修改总记录
// var repari = ""; //修改后的数量
// var repairrecord = "";
// for (var item in product) {
// repairrecord=product[item]; //记录当前的记录原始值
// productname = product[item].substring(0, product[item].indexOf(',')); //品名
// if (productname == name) {
// productprice = product[item].substring(product[item].indexOf(',') + 1); //数量
// repairrecord = productname + ',' + (parseInt(productprice)+1);
// }
// if (newproduct.substr(newproduct.length-1,1)=='|') {
// newproduct += repairrecord;
// } else {
// newproduct += repairrecord + '|';
// }
// //串回去
// }
// var thedate = new Date();
// thedate.setDate(thedate.getDate() + 1);
// document.cookie = newproduct + ';Expires=' + thedate.toGMTString()
// } else {
// //无此类商品
// alert("无此类");
// var thedate = new Date();
// thedate.setDate(thedate.getDate() + 1);
// var oldcookie = document.cookie;
// document.cookie = oldcookie +'|'+name+',1'+ ';Expires=' + thedate.toGMTString();
// }
// } else {
// //写入第一次的
// alert("第一次");
// var name = document.getElementById("disp").innerHTML;
// var thedate = new Date();
// thedate.setDate(thedate.getDate() + 1);
// var num = new Array();
// num[0] = name;
// num[1] = 1;
// var old = document.cookie + num;
// document.cookie = old + ';Expires=' + thedate.toGMTString();
// }
// }
function seekcart() {
if (document.cookie.length > 0) {
var name = document.getElementById("disp").innerHTML;
if (document.cookie.search(name) >= 0) { //判断是否记录存在
var cook = document.cookie;
var product = cook.split('|'); //分成单记录
var newproduct = ""; //修改总记录
var repari = ""; //修改后的数量
var repairrecord = "";
for (var item in product) {
repairrecord = product[item]; //记录当前的记录原始值
productname = product[item].substring(0, product[item].indexOf(',')); //品名
if (productname == name) {
productprice = product[item].substring(product[item].indexOf(',') + 1); //数量
repari = productname + ',' + (parseInt(productprice) + 1);
alert("'" + product[item].toString() + "'" + "=" + repari);
var s=cook.replace(repairrecord, repari);
cook = s;
}
// alert(s);
// alert(repairrecord);
// cook.replace(123, 456);
// if (newproduct.substr(newproduct.length,1) == '|') {
// newproduct += repairrecord;
// } else {
// newproduct += repairrecord + '|';
// }
//串回去
}
var thedate = new Date();
thedate.setDate(thedate.getDate() + 1);
document.cookie = cook + ';Expires=' + thedate.toGMTString()
} else {
//无此类商品
alert("无此类");
var thedate = new Date();
thedate.setDate(thedate.getDate() + 1);
var oldcookie = document.cookie;
document.cookie = oldcookie + '|' + name + ',1' + ';Expires=' + thedate.toGMTString();
}
} else {
//写入第一次的
alert("第一次");
var name = document.getElementById("disp").innerHTML;
var thedate = new Date();
thedate.setDate(thedate.getDate() + 1);
var num = new Array();
num[0] = name;
num[1] = 1;
var old = document.cookie + num;
document.cookie = old + ';Expires=' + thedate.toGMTString();
}
// document.write(document.cookie);
}
function Button2_onclick() {
document.write(document.cookie);
}
function Button4_onclick() {
if (document.cookie.length > 0) {
var name = document.getElementById("disp").innerHTML;
if (document.cookie.search(name) >= 0) { //判断是否记录存在
var cook = document.cookie;
var product = cook.split('|'); //分成单记录
var newproduct = ""; //修改总记录
var repari = ""; //修改后的数量
var repairrecord = "";
for (var item in product) {
repairrecord = product[item]; //记录当前的记录原始值
productname = product[item].substring(0, product[item].indexOf(',')); //品名
if (productname == name) {
productprice = product[item].substring(product[item].indexOf(',') + 1); //数量
repari = productname + ',' + (parseInt(productprice) + 1);
alert("'" + product[item].toString() + "'" + "=" + repari);
var s = cook.replace(repairrecord, repari);
cook = s;
}
// alert(s);
// alert(repairrecord);
// cook.replace(123, 456);
// if (newproduct.substr(newproduct.length,1) == '|') {
// newproduct += repairrecord;
// } else {
// newproduct += repairrecord + '|';
// }
//串回去
}
var thedate = new Date();
thedate.setDate(thedate.getDate() + 1);
document.cookie = cook + ';Expires=' + thedate.toGMTString()
} else {
//无此类商品
alert("无此类");
var thedate = new Date();
thedate.setDate(thedate.getDate() + 1);
var oldcookie = document.cookie;
document.cookie = oldcookie + '|' + name + ',1' + ';Expires=' + thedate.toGMTString();
}
} else {
//写入第一次的
alert("第一次");
var name = document.getElementById("disp").innerHTML;
var thedate = new Date();
thedate.setDate(thedate.getDate() + 1);
var num = new Array();
num[0] = name;
num[1] = 1;
var old = document.cookie + num;
document.cookie = old + ';Expires=' + thedate.toGMTString();
}
// document.write(document.cookie);
}
function Button5_onclick() {
if (document.cookie.length > 0) {
var name = document.getElementById("disp").innerHTML;
if (document.cookie.search(name) >= 0) { //判断是否记录存在
var cook = document.cookie;
var product = cook.split('|'); //分成单记录
var newproduct = ""; //修改总记录
var repari = ""; //修改后的数量
var repairrecord = "";
for (var item in product) {
repairrecord = product[item]; //记录当前的记录原始值
productname = product[item].substring(0, product[item].indexOf(',')); //品名
if (productname == name) {
productprice = product[item].substring(product[item].indexOf(',') + 1); //数量
repari = productname + ',' + (parseInt(productprice) - 1);
alert("'" + product[item].toString() + "'" + "=" + repari);
var s = cook.replace(repairrecord, repari);
cook = s;
}
// alert(s);
// alert(repairrecord);
// cook.replace(123, 456);
// if (newproduct.substr(newproduct.length,1) == '|') {
// newproduct += repairrecord;
// } else {
// newproduct += repairrecord + '|';
// }
//串回去
}
var thedate = new Date();
thedate.setDate(thedate.getDate() + 1);
document.cookie = cook + ';Expires=' + thedate.toGMTString()
} else {
//无此类商品
alert("无此类");
var thedate = new Date();
thedate.setDate(thedate.getDate() + 1);
var oldcookie = document.cookie;
document.cookie = oldcookie + '|' + name + ',1' + ';Expires=' + thedate.toGMTString();
}
} else {
//写入第一次的
alert("第一次");
var name = document.getElementById("disp").innerHTML;
var thedate = new Date();
thedate.setDate(thedate.getDate() + 1);
var num = new Array();
num[0] = name;
num[1] = 1;
var old = document.cookie + num;
document.cookie = old + ';Expires=' + thedate.toGMTString();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table class="style1">
<tr>
<td class="style2">
<img alt="" runat="server" id="img" src="" style="height: 207px; width: 511px" />
<div runat="server" id="disp" style="height: 13px; width: 143px">
</div>
</td>
<td>
件数:<input id="Text1" type="text" /><input id="Button3" type="button" value="购物" onclick="return Button3_onclick()" /></td>
</tr>
<tr>
<td class="style2">
<input id="Button1" type="button" value="购物" onclick="seekcart()" onclick="seekcart()" /><input
id="Button4" type="button" value="+" onclick="return Button4_onclick()" /><input id="Button5" type="button"
value="-" onclick="return Button5_onclick()" /></td>
<td>
<input id="Button2" type="button" value="查看" onclick="return Button2_onclick()" /></td>
</tr>
</table>
</form>
</body>
</html>
- JS+COOKIE购物车
- js+cookie+servlet(购物车)
- 原生js+cookie实现购物车功能
- COOKIE购物车
- jq+cookie 购物车
- 购物车--cookie+ajax
- 购物车cookie
- cookie实现购物车
- Cookie实现 购物车
- cookie实现购物车
- Cookie+DataList实现购物车
- 使用cookie实现购物车
- 用Cookie实现购物车
- php+cookie 实现购物车
- javascript购物车cookie存取
- 采用Cookie实现 购物车
- Cookie用于商品购物车
- js购物车
- 图形用户界面
- MFC添加用户自定义消息
- 第三周实验报告(任务3)
- .net下作业调度实战[quartz]
- Java 变量,数据类型的转换,若干算术运算符
- JS+COOKIE购物车
- Ubuntu增加swap交换空间
- nginx 服务器在windows下安装
- fedora 16安装 chrome
- 反转字符串中的单词
- windows phone 7 instance: ruler
- Linux3.0.6内核task_struct注释
- .NET 定时执行写日志任务解决方案(Timer & Quartz.Net)
- ios多核心 处理代码