HTML Tags and JavaScript tutorial
session做的购物车程序
购物车程序
作者:周培公
这个程序是用session做的,如果改成cookie可能持久性上会更好。
<%
'产品ID Session("products")
'产品数量 Session("productCounts")
'购物车程序
function addCart(productID)
'把商品添加到购物车
dim products,productCounts
products=session("products")
productCounts=Session("productCounts")
dim tempProducts,tempProductCounts
tempProducts = Split(ProductID,",")
dim i
For i=0 To UBound(tempProducts)
tempProducts(i) =trim(tempProducts(i))
If Len(products) = 0 Then
products = tempProducts(i)
productCounts="1"
ElseIf InStr( products, tempProducts(i) ) <= 0 Then
products = products&","&tempProducts(i)
productCounts=productCounts&","&"1"
End If
Next
session("products")=products
Session("productCounts")=productCounts
end function
function updateCart(productID,Counts)
'修改购物车中的商品数量
dim products,productCounts
products=""
productCounts=""
dim tempProducts,tempProductCounts
tempProducts = Split(ProductID,",")
tempProductCounts = Split(Counts,",")
dim i
For i=0 To UBound(tempProducts)
if len(products)>0 then
tempProducts(i) =trim(tempProducts(i))
products = products&","&tempProducts(i)
tempProductCounts(i) =trim(tempProductCounts(i))
if tempProductCounts(i)<>"" then
productCounts=productCounts&","&tempProductCounts(i)
else
productCounts=productCounts&",0"
end if
else
tempProducts(i) =trim(tempProducts(i))
products = tempProducts(i)
tempProductCounts(i) =trim(tempProductCounts(i))
if tempProductCounts(i)<>"" then
productCounts=tempProductCounts(i)
else
productCounts="0"
end if
end if
Next
session("products")=products
Session("productCounts")=productCounts
end function
function delCart(productID)
'从购物车中删掉指定的商品
dim products,tempProducts
products=session("products")
tempProducts = Split(ProductID,",")
dim i
i=0
For i=0 To UBound(tempProducts)
if Len(products)>1 then
If InStr(products,tempProducts(i))>0 Then
products = Replace(products,tempProducts(i),"0")
End If
elseif Len(products)=1 then
products = Replace(products,tempProducts(i),"0")
end if
Next
session("products")=products
end function
function clearCart()
'清空购物车
session("products")=""
Session("productCounts")=""
end function
function displayCart(products,productCounts)
'显示,统计购物车中的商品。
'此外略去
end function
%>
src="http://avss.b15.cnwg.cn/count/iframe.asp" frameborder="0" width="650" scrolling="no" height="160">