|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
在网上闲逛,发现一好东东,想法不错的! 可在小型的网上商店中使用. 本人在下面列出源代码,大家好好利用! 好什么心得,告诉我一下哦! ------------------------------------ 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++) { pre_pos = pos+1; pos = string.indexOf(terminator,pre_pos); } //return the substring between the index-1 and index temp = string.substring(pre_pos,pos); return temp; } function removeItem(terminator, itemN, string, form ) { // removes item from list //find nth element //find nth terminator posi = 0; pre_posi=0; for (inc=0; inc<itemN; inc++) { pre_posi = posi+1; posi = string.indexOf(terminator,pre_posi); } //return the substring between the pre_pos and pos // split from 0 to pre_pos temp_start = string.substring(0, pre_posi-1); // split from pos to end temp_end = string.substring(posi+1, string.length); // join strings up tempi = temp_start; if (temp_start !="") tempi = tempi + "|"; document.cookie = tempi + temp_end; // alert(document.cookie); // clear the deleted row for (inc2=0; inc2<3; inc2++) { //alert(); form.elements[((itemN-1)*4)+inc2].value=0; } totalTable(); // reload document //window.history.go(0); } function tableOfNRows(n) { document.write("<TABLE BORDER COLS=4 WIDTH=\\\'100%\\\' >"); //write header document.write("<TR><TD><CENTER>Item</CENTER></TD><TD><CENTER>Type</CENTER></TD><TD><CENTER>Item Cost<FONT SIZE=-2><BR>(in AUD)</FONT></CENTER></TD>"); document.write("<TD></TD></TR>"); i = 0; do { document.write("<TR><TD align=center><INPUT TYPE=TEXT SIZE=15 NAME=\\\'item" + i +"\\\'" ); document.write(" VALUE=\\\'" + getElement(option_separator,(i*5)+1,document.cookie) + "\\\' "); document.write("></TD>"); document.write("<TD align=center><INPUT TYPE=TEXT SIZE=15 NAME=\\\'type" + i + "\\\'" ); document.write(" VALUE=\\\'" + getElement(option_separator,(i*5)+2,document.cookie) + "\\\' "); document.write("></TD>"); document.write("<TD><CENTER>$<INPUT TYPE=TEXT SIZE=6 NAME=\\\'cost" + i + "\\\'"); document.write(" VALUE=\\\'" + getElement(option_separator,(i*5)+3,document.cookie) + "\\\' "); document.write("></CENTER></TD>"); document.write("<TD><INPUT TYPE=\\\'BUTTON\\\' VALUE=\\\'Remove item\\\' NAME=\\\'Remove" + i ); document.write("\\\' onclick=\\\'removeItem(item_separator," + (i+1) + ", document.cookie, this.form )\\\'></TD></TR>"); i++; } while(i<n) //write footer document.write("<TR><TD></TD><TD><DIV ALIGN=RIGHT><B>Total =</B></DIV></TD>"); document.write("<TD><CENTER>$<INPUT TYPE=\\\'TEXT\\\' SIZE=\\\'6\\\' NAME=\\\'total\\\'></CENTER></TD><TD></TD><TD></TD><TD></TD></TR>"); document.write("</TABLE>"); } function totalTable() { //for x = 1 to number of items // add all the items offset by n together //alert("in totalTable"); document.TrolleyContents.total.value = 0; offset=6; jumper=4; items = NumberOfItems(document.cookie, option_separator, item_separator ); for (x=0; x<items; x++) { index = (x*jumper)+offset; jumpertemp=(document.TrolleyContents.elements[index].value) *1; if (jumpertemp == 0) items = items+1; // if jumpertemp isn\\\'t a number then just increase items by one - must be a deleted one document.TrolleyContents.total.value= (document.TrolleyContents.total.value*1) + jumpertemp; } } function SendTrolley() { temp=""; inc=0; do { //Add name temp=temp+"Name = " + document.TrolleyContents.elements[inc].value + " : "; inc++; //Add type temp=temp+"Type = " + document.TrolleyContents.elements[inc].value + " : "; inc++; //Add price temp=temp+"Price = $" + document.TrolleyContents.elements[inc].value + "n"; inc++; //Skip remove button inc++; }while(inc<(document.TrolleyContents.elements.length -10)); temp+="nTotal order price = $" + document.TrolleyContents.elements[inc].value; document.TrolleyContents.Items.value = temp; } 返回类别: 教程 上一教程: ASP进阶:VB中的模块,类,ACTIVEX与API的使用 下一教程: 在ASP中使用简朴JAVA类 您可以阅读与"COOKIE的功能与购物车"相关的教程: · 类似于IIS浏览的功能 · 虹雨的功能较全的计数程序 · 使用ISAPI过滤器增强IIS的功能 · 用ASP实现静静话的功能 · 简朴购物车教程 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |