日期:2013-05-26  浏览次数:21228 次

cookie的功能与购物车   
zif 发表于2000-01-11 16:13:00   

在网上闲逛,发现一好东东,想法不错的!
可在小型的网上商店中使用.
本人在下面列出源代码,大家好好利用!
好什么心得,告诉我一下哦!
------------------------------------
products.html
<html>
<head>
<title>Claremont Toyworld</title>
<script LANGUAGE="JAVASCRIPT">
function SetCookie(name, price, form) {
document.cookie= document.cookie + ":" + name + ":";
document.cookie= document.cookie + "" + ":";
document.cookie= document.cookie + price + ":";
document.cookie= document.cookie + "" + ":";
document.cookie= document.cookie + "|" + ";";
}
</script>
</head>
<body text="#000000" bgcolor="#FFFF00" link="#0000EE" vlink="#551A8B" alink="#FF0000">
<a href="trolley.html">here.</a>
<table BORDER="0" CELLSPACING="0" CELLPADDING="0" COLS="3" width="75%">
<tr>
<td><strong>Furby</strong></td>
<td>The Amazing Pet</td>
<td><small>AUD</small> $69.95<font size="-2"> + <a href="#Postage">postage</a></font></td>
<td><form>
<p><input TYPE="BUTTON" VALUE="Add to cart" NAME="Additem1"
onclick="SetCookie('Furby','69.95', this.form);"></p>
</form>
</td>
</tr>
</table>
</body>
</html>
----------------------------------------
trolley.html
<html>
<script LANGUAGE="JAVASCRIPT" src="trolley.js">
</script>
</head>
<body>

<table COLS=2 WIDTH="100%" >
<tr>
<td>
</td>
</tr>
</table>
<form name="TrolleyContents" ACTION="formmail.pl" METHOD="POST" ><input type="hidden" name="email" value="email">

<script LANGUAGE="JAVASCRIPT">
tableOfNRows(NumberOfItems(document.cookie, option_separator, item_separator));
</script>

<table COLS=4 WIDTH="100%" >
<tr>
<td><input type="button" value="<-- Back to shopping" onclick="window.close();"></td>

<td><input type="button" value="Clear shopping trolley" onclick="ClearTrolley();"></td>

<td> <a href="#Finalise">Finalise order</a></td>

<td> </td>
</tr>
</table>

<h1>
<script LANGUAGE="JAVASCRIPT">
totalTable();
</script>

</body>
</html>
----------------------------------------
trolley.js
// rem trolley.js source Copyright Prestige Training Centre

option_separator = ":";
item_separator = "|";

function NumberOfItems(string, option_separating_char, item_separating_char) {
// returns the number of trolley items

if(string == "") {
alert("Your shopping trolley is currently empty.");
return 0;
}

//count the number of item separators
num_sep_found = 0;
num_fin_found = 0;
finished = -1;
pos = 0;
while(finished!=1)
{
if(string.charAt(pos) == option_separating_char) num_sep_found++;
if(string.charAt(pos) == item_separating_char)
{
num_fin_found++;
if(string.charAt(pos+1) != option_