Heim > Web-Frontend > js-Tutorial > Hauptteil

Vollständige Version des Warenkorbprogramms (JavaScript-Code)

高洛峰
Freigeben: 2016-11-26 10:13:40
Original
1420 Leute haben es durchsucht

[javascript]
/*********************************Warenkorb-Kategorie****************** **** **********************/ 
 
    var product=function(productArr){/*商品类基类productArr=>array;productArr['ID'], productArr['name'],productArr['pic'],=productArr['lvs'],productArr['width'],productArr['thickness'],productArr['length'],productArr['open'], productArr['capacity']*/ 
        var _ID=productArr['ID'],_name=productArr['name'],_pic=productArr['pic'],_price=productArr['price'],_weight= productArr['weight'],_originalPrice=productArr['originalPrice'],_this=this; 
        this.num=productArr['num']; 
        this.getName=function(){ 
            return _name; 
            } 
        this.getID=function(){ 
            return _ID; 
            }    
        this.getPrice=function(){ 
            return _price; 
            } 
        this.getWeight=function(){ 
            return _weight; 
            } 
        this.getPic=function(){ 
            return _pic; 
            } 
        this.getOriginalprice=function(){ 
            return _originalPrice; 
            } 
        this.setNum=function(newNum){ 
            _this.num=newNum; 
            } 
        this.getTotal=function(){ 
            var total=_this.num*_this.getPrice(); 
            Gesamtrückgabe; 
            }    
         制造的product对象,gID=>数据组ID, pID=>商品ID 
            /*********Herstellungscode*********/ 
            var pData=[]; 
            (function(gID,pID){ 
                $.ajax({ 
                   url:'/module/data/default.php?action=dataDetail&groupID='+gID+'&ID='+pID+'& r= '+newDate(), 
                   type:'post', 
                   dataType:'xml', 
                  . async:false, 
                    /**Werksmethode***/ 
                    success:function(dataXML ){ 
                       pData.price=$(dataXML).children('root').children('extend19').text(); 
                        pData.originalPrice=$(dataXML).children('root').children('extend9').text(); 
                        pData.weight=$(dataXML).children('root').children('extend21').text(); 
                        pData.name=$(dataXML).children('root').children('name').text(); 
                        pData.pic=$(dataXML).children('root').children('extend17').text(); 
                        } 
                    }); 
                })(gID,pID);         preis:pData.price, 
                pic:pData.pic, 
               weight:pData.weight, 
                originalPrice:pData.originalPrice, 
                }); 
        } 
    var cartCookie=$.cookies.get('productItem');//cookie的全局变量=>'商品ID|数量,商品ID|数量' 
    //alert(mockCookie) ; 
     
    var productCollection=function(){//商品搜集类 
            var products=[]; 
            var hasOne=function(productObj){ 
                var isOne=0;  _nowCollection.setNumByPid(pID,newNum);
}                                          .getCurrentNumByPid=function(pID){//Erhalten Sie die Menge eines bestimmten Produkts, pID->Product ID
var productObj=_nowCollection.getProductById(pID); 🎜>                                                                                                                                                                                  
Dies. getTotalMoney=function(){//Erhalten Sie den Gesamtbetrag
var _money=_nowCollection.getNeedMoney();
return _money; Den Gesamtbetrag eines einzelnen Produkts abrufen
var _needProduct=_nowCollection.getProductById(pID); throw new Error('No such product');            var _totalMoney=_needProduct.getTotal();                         .renderCart=function (){//Rendering-Funktion
                                                                 In der Unterklasse implementiertthrow new Error('Fehler, diese Methode muss in der Unterklasse implementiert werden');
                                                                                                      .com
_this.renderCart();
_this.bindEvent(); .Get NewCollection = function () {// Erhalten Sie ein neues Sammlungsobjekt
>/** **************************Warenkorb-Kategorie******************** * ***************************/
*************prüfen*****************/
carttest.rendercart = function () {// sub- rendern
var _content='';                                                                ().getProducts()[i];
                                                                                                                                                   _content+=''+_productEach.getName()+'$'+_productEach.getOriginalprice()+'$'+_productEach.getPrice()+''+_productEach.getWeight()+'Kg-'+_productEach.num+'+$'+_productEach. getTotal()+'Delete                                } 
                            //document.write(_content); 
                            //alert(_content); 
                            $('#checkCart').find('tr').eq(0).after(_content);//Weitere Informationen total_right‘) .children('span').html('$'+cartTest.getTotalMoney()); 
                          /**popBoxCount**/               }//renderCart 
                                                   var _this=this; 
                                   //alert($('#'+win1.ID).find('.cartList').eq(0).html()); 
                                  every=$(this); 
                                            _each.find('td:last').css('cursor','pointer').click(function(){ 
                                          . //alert('删除'); 
                                                var _tempThis=$(this) ; 
                                         _this.delProduct($(this).parents('tr').find('td:first').find('input[type=hidden]').val());                                          $ (this).parents('tr').remove(); 
                                                      $('.step_total').find('.step_total_right').children('span' ).html('$'+_this.getTotalMoney()); 
                                            /*******Berechnen Sie den Gesamtbetrag des Artikels neu******                                       });//click删除商品                                            _each.children('td[ class=numJia]').css('cursor','pointer').click(function(){ 
                                                  var _jiaThis=$(this); 
                                                   //alert($(this).parents('tr').parents('table').find('input[type=hidden]').val()); 
                                                    _this.setNumByPid($(this).parents('tr').find('td:first').find('input[type=hidden]').val(),_this.getCurrentNumByPid($(this). parent('tr').find('td:first').find('input[type=hidden]').val())+1); 
                                                   //alert(_jiaThis.parents('td').siblings('td[class=nowNum]').children('input').val()); 
                                              . _jiaThis.siblings('td[class=nowNum]').html(                                                _this.getCurrentNumByPid(_jiaThis.parents('tr').find('td:first').find('input[type =hidden]').val()) 
                                                   ); 
                                              . /***********Gesamtbetrag eines bestimmten Artikels neu berechnen***********/                                               _jiaThis.siblings('td[class=eachTotal]').children('span').html('$'+_this.getTotalMoneyByPid(_jiaThis.parents(' tr').find('td:first').find('input[type=hidden]').val())); 
                                                   /***********Berechnen Sie den Gesamtbetrag eines bestimmten Artikels neu*************/ 
                                                                                                       $('.step_total').find('.step_total_right').children('span') .html('$'+_this.getTotalMoney()); 
                                                   /*******Berechnen Sie den Gesamtbetrag des Artikels neu*******/ 
                                                });//click增加商品数量 
                                       . _each.children('td[class=numJian]').css('cursor','pointer').click(function(){ 
                                                    var _jianThis=$ (this);                                               if(_this.getCurrentNumByPid($(this).parents('tr').find('td:first').find('input[type=hidden]').val()) >1){ 
                                                     _this.setNumByPid($(this).parents('tr').find('td:first').find('input[type=hidden]').val(),_this .GetCurrentNumbypID ($ (this) .Parents ('tr'). Find ('td: First'). Find ('Eingabe [type = versteckt]'). Val ())-1); ('td[class=nowNum]').html( 
                                                     ').val()) 
                                                );                                    /***********Gesamtbetrag eines bestimmten Artikels neu berechnen***********/ 
                                                  _jianThis.siblings('td[class=eachTotal]').children('span').html(' $'+_this.getTotalMoneyByPid(_jianThis.parents('tr').find('td:first').find('input[type=hidden]').val())); 
                                              . /***********Gesamtbetrag eines bestimmten Artikels neu berechnen***********/                                                
/*******Berechnen Sie den Gesamtbetrag des Artikels neu*******/
                                                                                  🎜> /** */
} // Wenn die aktuelle Anzahl der Produkte größer als 1 ist
}); products
}); // Each
} // bindevent
Carttest.touchoff (); // Trigger

$ (Window) .unload (function () {// Beim Verlassen die Seite
// Alert ('Dog head');
var _products = LastCollection.getProduts ();
//console.Loguts.length; VAR _C Artcookie = '';
var _Countnum = 0 ; '+_ products[i].num+','
_countNum+=_products[i].num*_products[i].getWeight();                            _cartCookie=_cartCookie.substring(0,_cartCookie.length-1); 
                            //alert(_cartCookie); 
                            //alert(_cuntNum); 
                            //alert(_countNum); 
                            $.cookies.set('productItem',_cartCookie);//设置Cookie量的Cookie 
                        }); 
                         🎜>                          var _listProducts=cartTest.getNewCollection().getProducts(); if(_listProducts.length<0||_listProducts.length==0){ 
                                Alert('Bitte Produkte auswählen!');                     🎜>                                } 
                            window.location.href="http ://www.php1.cn/">                         }); 
                  
    var cartTest=new cart(); 
    cartTest.setCollection(productCollections); 
    neuer ShoppingTrolley(); 

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage