一、购物车程序的规划功能模块有: 添加物品、删除物品、清空购物车、修改购买物品数量在物品展示页面以物品的 ID 号为参数来运行 JS 函数 PutWare(strID) PutWare(strID) 函数内容如下: <script language="JavaScript"> function PutWare(strID){ Shopwin=("?action=add&spid="+strID+" &PtCount=1",'WareList','width=580,height=250,scrollbars=yes,resiz a ble=yes'); (); } </script> 此函数功能,打开购物车 并传传递当前页变量参数( acction,id,ptcount ) 物品展示外的调用如下: 添 加物品: <a href="javascript : ;" onClick ="PutWare('<%=trim(rs("id"))%>')"> 放入购物车</a> 二、添加商品代码分析: <% '添加商品 if request("action")="add" then call AddProduct(request("spid"),CInt(request("PtCount"))) end if %> 此段判断是否要放物品在购物车中, 如果是的话, 调用 AddProduct(strPcID,intCount) 过程,过程代码如下: <% sub AddProduct(strPcID,intCount) ProductList = Session("ProductList") '商品 ID 列表 ProductCount=Session("ProductCount") '商品数量列表 Products = Split(ProductList, ",") '分割物品种类为数组 PtCounts = Split(ProductCount, ",") '分割物品数量为数组'下面为寻求购物车中是否有该商品,如果没有则追加 For i=0 To UBound(Products)' 返回 Product s 的元素个数, 及数组 Product s 的最大的下标。 if Products(i)=strPcID then exit for Next '还没有该商品,追加 if i>UBound(Products) then Session("ProductList") = ProductList & strPcID & "," Session("ProductCount") = ProductCount & intCount & "," else '如果商品已在车中,累加数量 PtCounts(i)=Cint(PtCounts(i)) + intCount Session("ProductList") =join(Products,",") Session("ProductCount") =join(PtCounts,",")' 将数组转换成字串 end if end sub %> 三、删除商品代码分析: 删除物品: <input type="button" name="Submit" value=" 删除" onClick ="DeleProduct('<%=rs("id")%>')"> <% if request("action")="modiy" then call ModifyProduct(request("spid"),CInt(request("PtCount"))) end if %> 此段判断是否要删除购物车中的指定物品,如果是的话,调用 ModifyProduct(strPcID,intCount) 过程,过程代码如下: <% sub ModifyProduct(strPcID,intCount) ProductList = Session("ProductList") '商品 ID 列表 ProductCount=Session("ProductCount") '商品数量列表 Products = Split(ProductList, ",") PtCounts = Split(ProductCount, ",") '寻求购物车中是否有该商品,如果有则删除 For i=0 To UBound(Products) if Products(i)=strPcID then exit for Next '还有该商品,删除该商品指定的数量 if i<=UBound(Products) then PtCounts(i)=intCou
购物车程序的规划 来自淘豆网m.daumloan.com转载请标明出处.