WEB开发网      婵犵數濞€濞佳囧磹婵犳艾鐤炬い鎰堕檮閸嬬喐銇勯弽銊с€掗梻鍕閺岋箑螣娓氼垱笑闂佽姘﹂褔婀佸┑鐘诧工妤犲憡绂嶉崜褏纾奸弶鍫涘妼缁楁岸鏌熷畡鐗堝殗闁诡喒鏅犲畷褰掝敃閵堝棙顔忔繝鐢靛仦閸ㄥ爼骞愰幘顔肩;闁规崘绉ぐ鎺撳亹闁绘垶锕╁Λ鍕⒑閹肩偛濡奸悗娑掓櫇缁顓兼径妯绘櫇闂佹寧绻傞弻濠囨晝閸屾稓鍘甸柣搴㈢⊕閿氶柣蹇ョ稻缁绘繃绻濋崘銊т紝闂佽鍨伴崯鏉戠暦閻旂⒈鏁傞柛鈾€鏅欑槐妯衡攽閻愬樊鍤熷┑顔藉劤铻為柛鏇ㄥ墯閸欏繘鏌嶉崫鍕櫣缂佲偓婢跺绠鹃柟瀛樼箘閿涘秵顨ラ悙顏勭伈闁诡喖缍婂畷鎯邦槻婵℃彃顭烽弻娑㈠Ω閵夈儺鍔夌紓浣稿€哥粔褰掑极閹剧粯鏅搁柨鐕傛嫹 ---闂傚倷鐒︾€笛兠洪埡鍛闁跨噦鎷�
开发学院WEB开发ASP 购物车范例(处理页面) 阅读

购物车范例(处理页面)

 2001-11-23 11:06:18 来源:WEB开发网 闂傚倷绶氬ḿ褍螞閹绢喖绠柨鐕傛嫹闂傚倷绀侀幉锟犲垂閻㈠灚宕查柟鎵閸庡秵銇勯幒鎴濃偓鐢稿磻閹炬枼妲堟繛鍡楃С濞岊亞绱撻崒姘扁枌闁瑰嚖鎷�婵犵數濮幏鍐川椤撴繄鎹曢梻渚€娼уú銈吤洪妸鈺佺劦妞ゆ帊鑳堕埊鏇㈡煏閸モ晛浠х紒杈╁仱閺佹捇鏁撻敓锟�闂傚倷绶氬ḿ褍螞閹绢喖绠柨鐕傛嫹  闂傚倷鑳舵灙缂佺粯顨呴埢宥夊即閵忕姵鐎梺缁樺姇閹碱偆鐥閺屾洘绻濊箛鏇犵獥闂佺厧澹婃禍婊堚€旈崘顏佸亾閿濆骸澧ù鐘欏嫮绠鹃柛顐ゅ枎閻忋儲銇勯弴妯哄姦妞ゃ垺鐟╅幃鈩冩償閵囧府鎷�
核心提示:<!--put2bag.asp--><%@ Language=VBScript %><%'id_type=request("id_type")on error resume nextResponse.Buffer = trueResponse.Expires =
<!--put2bag.asp-->

<%@ Language=VBScript %>
<%
  'id_type=request("id_type")

  on error resume next
  Response.Buffer = true
  Response.Expires = 0
  dim obj_bag,bag_item,cart
      'obj_bag   ----购物车
      'bag_item   ----商品的信息数据集合
      'cart     ----一件商品的信息数据集合
  dim p_id,p_name,p_PRice,p_manu,p_type,p_size,p_color,p_num,p_temp
      'p_id        ----商品id号
      'p_name     ----商品名称
      'p_price      ----原价单价
      'p_manu     ----商品制造商
      'p_type      ----商品式样
      'p_size      ----商品尺寸
      'p_color      ----商品颜色
      'p_num      ----商品数量
      'p_temp      ----临时存放p_num
      

  if session("login")="" then
    response.write"<script langue=""javascript"">" & chr(13)
    response.write"alert(""请先登录"");" & chr(13)
    response.write"history.go(-1);" & chr(13)
    response.write"</script>" & chr(13)
  else
        '初始化购物车内变量
    p_id=trim(request("id"))
    P_manu=trim(request("manu"))
    p_type=trim(request("type"))
    p_name=replace(trim(request("name1"))," ","")
    p_price=trim(request("price"))
    p_size=trim(request("size"))
    p_color=trim(request("color"))
    p_num=trim(request("num"))

    if ((not IsNumeric(p_num)) or (p_num<="0") or (instr(1,p_num,".")<>0)) then
      p_num=1         ‘如果商品数量小于0或者有小数点,取1
    end if
    
    if p_name <>"" then
            '如果有购物信息传入则准备装如购物车
            '如果还没有购物车则新建dictionary对象

      if isobject(Session("Bag")) then  '如果有购物车则更新
      'response.write "isobject(Session(""Bag""))=" & isobject(Session("Bag")) & "<br>"
        set obj_bag=Session("Bag")
        if obj_bag.exists(p_name) then   ''如果当前购物车中已有该商品
          if err then
            response.write err.description
            err.clear
          end if
          
          'response.write isobject(obj_Bag)

          p_temp=obj_bag.item(p_name)(6) '将p_num的值存放于p_temp中
          response.write "p_num=" & p_num & "<br>"
          p_num=cint(p_num)+cint(p_temp) '购买的商品数量累加
       
          bag_item=array(p_name,p_manu,p_type,p_size,p_color,p_price,p_num,p_id)
          obj_bag.item(p_name)=bag_item
         else            
          bag_item=array(p_name,p_manu,p_type,p_size,p_color,p_price,p_num,p_id)
          obj_bag.Add p_name,bag_item
        end if
     
      else                           '没有购物车生成新的
        set obj_bag=server.CreateObject ("Scripting.Dictionary")
        bag_item=array(p_name,p_manu,p_type,p_size,p_color,p_price,p_num,p_id)
        response.write bag_item(0)
        obj_bag.Add p_name,bag_item
      end if  
      set Session("Bag") = obj_Bag  '更新购物车
    end if
    
    Response.Redirect ("checkbag.asp?obj="& request("obj") &"") '转向显示购物车页面
  end if
%>

Tags:购物车 范例 处理

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接