cookie的功能與購物車

來源:互聯網
上載者:User
cookie|購物車 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_separating_char) finished=1;
}
pos++;
}

//divide by the number of 'ends' found

num_sep_found = num_sep_found - num_fin_found;

//if(num_fin_found >0) return num_sep_found/num_fin_found;

return num_fin_found;

}

function ClearTrolley() {
if (confirm("Clear the contents of your shopping trolley?"))
{
document.cookie="";
history.back();
}
}

function getElement(terminator,index,string) {

//find nth terminator
pos = 0;
for (inc=1; inc<index+1; inc



相關文章

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。