⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shopcar.inc

📁 都乐电子书店!!! !!! !!! !1
💻 INC
字号:

<script language="javascript">

//调整选购数量
function inc(form){
     var myform = "";
     bookid = form.elements[0].value;
     bookname = form.elements[1].value;
     publish = form.elements[2].value;    
     unitprice = form.elements[3].value;
     num = form.elements[4].value;
     
    
    if (num<1){
        window.alert ("订购数量最少为 1 !");
    }else {
        setcookie("dule"+bookid,bookid,bookname,publish,unitprice,num);
        location.href = "default.asp?job=shopcar";
    }   
}

function convert(num){
         aa=num*10;
         aa=Math.round (aa);
         aa=aa/10;
         return aa;
}


function setcookie(cookiename,bookid,bookname,publish,unitprice,num)
{
    var expiryday = new Date();
    expiryday.setTime(expiryday.getTime() + 3*30*60*1*1000);
    var valuestr = "bookid" + bookid + "|" + 
                   "bookname" + bookname + "|" +
                   "publish" + publish + "|" + 
                   "unitprice" + parseFloat(unitprice) + "|" + 
                   "num"+ parseFloat(num);                                
    var namestr = cookiename + "=" + valuestr;
    var expirystr = "expires" + "=" + expiryday.toGMTString();
    var amount = parseInt(num);
    if (!isNaN(amount))
        document.cookie = namestr + ";" +
                          expirystr + ";" +
                          "path=/";
  window.alert("cookie:" + document.cookie);
}

function getitem(onecookie,Itemname){
var ItemFound = false;
var start = 0;
var end = 0;
var whole_length = onecookie.length;
var start = 0;
    while (start<whole_length){
           end = start+Itemname.length;
           if (onecookie.substring(start,end) == Itemname){
               ItemFound = true;
               break;
           }
           start++;
   }
   
   if (ItemFound){
       start = end;
       end =onecookie.indexOf("|",start);
           if (end < start)
              end = onecookie.length;
           return unescape(onecookie.substring(start,end));           
   }
   return "";    
}

function MakeArray(n){
         this.length = n;
         for(var i=0;i<=n-1;i++)
             this[i] = 0;
             return this;
}
 
var Arraylength = 0;
var mycookie = new MakeArray(100);

function dispose_cookie(){
         var startpoint = 0;
         var endlocation = 0;
         var i = 0;
         var cookie = "";
         whole_length = document.cookie.length;
       // window.alert("length:"+whole_length);
         
    while(whole_length > startpoint && i < 100)
    { 
        if((endlocation = document.cookie.indexOf(";",startpoint)) != -1)
        { 
            cookie = document.cookie.substring(startpoint,endlocation);
            if (cookie.indexOf("dule", 0) > -1) {
                mycookie[i] = cookie;
                i++;
            } else {
                dele(cookie);
            }
            startpoint = endlocation+1;
        }
        else if (startpoint < whole_length)
        {
            cookie = document.cookie.substring(startpoint,whole_length);
            if (cookie.indexOf("dule", 0) > -1) {
                mycookie[i] = cookie;
                i++;
            } else {
                dele(cookie);
            }
            startpoint = whole_length;
        }
    } 
    Arraylength = i;
}


TotalPay = 0.0;
Total_price = "";
bookid = "";
bookname = "";
publish = "";
unitproce = "";
num = "";


function view_cart(){
     var i = 0;
     dispose_cookie();
     printtile();
     
     for (i = 0;i < Arraylength;i++){
          bookid=getitem(mycookie[i],"bookid");
          bookname=getitem(mycookie[i],"bookname");
          publish=getitem(mycookie[i],"publish");
          unitprice=getitem(mycookie[i],"unitprice");
          num=getitem(mycookie[i],"num");
          Total_price = parseFloat(unitprice) * parseInt(num);
          Total_price = convert(Total_price);
          TotalPay += parseFloat(Total_price);
          TotalPay = convert(TotalPay);
          
          printcontent(); 
     }
	 printfoot();
     //printtotalprice();
    
}

function printtile(){
         tabletitle = "<br><table align=center border=0 cellpadding=0 cellspacing=1 width=86% bgcolor=#6666ff>"                     
					  +"<tr bgcolor=#e8e8e8><td width=35%>书名</td>"
                      +"<td width=20% height=30>出版社</td>"
                      +"<td width=15% height=30>数量</td>"
                      +"<td width=10% height=30>单价</td>"
                      +"<td widht=10% height=30>合计</td>"
					  +"<td width=10% height=30></td></tr>";
        document.write (tabletitle);                
}

function printfoot(){
      if (Arraylength>0){
          foot = "<tr bgcolor=#e8e8e8><td colspan=6 align=right height=30> 总计:"+ TotalPay+"&nbsp;&nbsp;</td></tr>"	   
              +"<tr bgcolor=#ffffff><td colspan=6 align=center height=30>"
			  +"<input class='inputbox' type=button value=会员柜台结算 id=button1 onclick=location.href='default.asp?job=counter1'>&nbsp;&nbsp;"
			  +"<input class='inputbox' type=button value=普通柜台结算 id=button2 onclick=location.href='default.asp?job=counter2'>&nbsp;&nbsp;"
              +"<input class='inputbox' type=button value=清空购物车 id=button3 onclick='return empty_all()'>&nbsp;&nbsp;"
              +"<input class='inputbox' type=button value=继续购书 id=button4 onclick='history.back()'>"
              +"<br><br>注意:1. 如果你是我们都乐的会员,请到会员柜台结算<br><br>2. 如果你还不是我们都乐的会员,请到普通柜台结算</td></tr></table>"
          } else {
            foot="<tr bgcolor=#ffffff><td colspan=6 height=30 align=center>目前你的购物车没有书,请继续购书</td></tr></table>"
          }
 document.write (foot);
}

function printcontent(){
      if (num != 0){
          document.write ("<tr bgcolor=#ffffff>");
          document.write ("<form method=post>");
          document.write ("<input type=hidden name=bookid value="+bookid+">");
          document.write ("<input type=hidden name=bookname value="+bookname+">");
          document.write ("<input type=hidden name=publish value="+publish+">");
          document.write ("<input type=hidden name=unitprice value="+unitprice+">");
          document.write ("<td height=30 ><a href='display.asp?bookid="+bookid+"'>"+bookname+"</a></td>");
          document.write ("<td height=30 >"+publish+"</td>");
          document.write ("<td height=30 ><input class='inputbox' type=text size=4 maxlength=4 value="+num+" name=num>");
		  document.write ("&nbsp;<input class='inputbox' type=button value=调整 onclick='return inc(this.form);'></td>");
          document.write ("<td height=30 >"+unitprice+"</td>");
          document.write ("<td height=30 >"+Total_price+"</td>");
		  document.write ("<td height=30 ><input class='inputbox' type=button value=取消 onclick=\"dele('dule"+bookid+"');refresh();\">");
          document.write ("</td></form></tr>");
      }
}

function refresh ()
{
    location.href='default.asp?job=shopcar';
}


function dele(onecookie)
{ 
    document.cookie=onecookie+"=bb; expires=Saturday, 16-Sep-90 23:59:59 GMT; path=/";
}

function empty_all(){
     var i = 0;
     var cookie_id = "";   
     dispose_cookie();
     
     if (window.confirm ("确认清空购物车?")){
       for (i = 0;i<Arraylength;i++){
         cookie_id = getitem(mycookie[i],"bookid");
         dele("dule"+cookie_id); 
       }
       location.href = 'default.asp?job=shopcar';
     }
}
  
  </script>
    
<br>&nbsp;&nbsp;<img src="images/ok.gif">当前你的购书情况:
 <a href=default.asp>继续购书</a>   
 
<script language="javascript">
   view_cart();
</script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -