shoppingCart.js
2014-07-18 07:47
267 查看
ylbtech-JavaScript-util: shoppingCart.js |
1.A,JS-效果图返回顶部 |
1.B,JS-[b][b]Source Code[/b]([b]源代码)[/b][/b]返回顶部 |
/* */ function Product() { var itemcode; //商品编码 var count; //数量 var type; //类型 var paramid; //参数 } /* 添加商品 */ function addShoppingCartProduct(itemCode, count, type, paramid) { if (itemCode == "" || itemCode == null) { alert("商品编号不能为空!"); return false; } var productList = getShoppingCartProductList(); var found = false; var i = 0; while (i < productList.length) { var productInfo = productList[i]; if (productInfo.itemcode == itemCode) { productInfo.count = productInfo.count + count; productInfo.type = type; productInfo.paramid = paramid; found = true; break; } i++; } if (!found) { product = new Object(); product.itemcode = itemCode; product.count = count; product.type = type; product.paramid = paramid; productList.push(product); } localStorage.shoppingCartProductList = JSON.stringify(productList); return true; } /* 取得商品 */ function getShoppingCartProduct(itemCode) { var productList = getShoppingCartProductList(); var i = 0; while (i < productList.length) { var productInfo = productList[i]; if (productInfo.itemcode == itemCode) { return productInfo; } i++; } return null; } /* 取得商品列表 */ function getShoppingCartProductList() { if (localStorage.shoppingCartProductList == undefined || localStorage.shoppingCartProductList == "undefined" || localStorage.shoppingCartProductList == "") { var newProductList = new Array(); localStorage.shoppingCartProductList = JSON.stringify(newProductList); } var productList = JSON.parse(localStorage.shoppingCartProductList); return productList; } /* 清空购物车 */ function clearShoppingCart() { var productList = new Array(); localStorage.shoppingCartProductList = JSON.stringify(productList); } /* 删除商品 */ function removeShoppingCartProduct(itemCode) { var productList = getShoppingCartProductList(); var i = 0; while (i < productList.length) { var productInfo = productList[i]; if (productInfo.itemcode == itemCode) { productList.splice(i, 1); break; } i++; } localStorage.shoppingCartProductList = JSON.stringify(productList); } /* 修改商品数量 */ function updateShoppingCartProduct(itemCode, count) { var productList = getShoppingCartProductList(); var i = 0; while (i < productList.length) { var productInfo = productList[i]; if (productInfo.itemcode == itemCode) { productInfo.count = count; break; } i++; } localStorage.shoppingCartProductList = JSON.stringify(productList); }
View Code
1.B.2,
1.C,JS[b][b]-Relevent References(相关引用)[/b][/b]返回顶部 |
作者:ylbtech 出处:http://ylbtech.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |
相关文章推荐
- How to Pick a Shopping Cart(如何为网站选择一个网络购物车)
- Duwamish7中ShoppingCart页面的错误。
- MVC Music Store 在线音乐商店示例分析(10)ShoppingCartController
- Magento——利用购物车促销规则(Shopping Cart Price Rules)实现自己的功能第一章: 添加新的动作(Actions)
- How to Scan a Shopping Cart with an Automated Security Scanner
- Magento——利用购物车促销规则(Shopping Cart Price Rules)实现自己的功能第二章: 购物车页面判断设置的规则和动作
- MVC Music Store 在线音乐商店示例分析(13)View(Account、Checkout、Home、Shared、ShoppingCart)
- asp shopping cart
- LittleItalyVineyard案例分析中关于ShoppingCart删除商品后TotalMoney不变0的bug
- Building an ASP.NET Shopping Cart Using DataTables
- js简单的shopping
- SQL_ShoppingCart / ShoppingCartAddItem / ShoppingCartGetItems / ShoppingCartGetTotalAmount / ShoppingCartRemoveItem ...
- MVC Music Store 在线音乐商店示例分析(6)ShoppingCart
- 购物车(Shopping cart) —— B2C网站核心产品设计 (二)
- Struts框架 ShoppingCart
- shopping cart made by JSP
- ASP.NET 2.0个性化配置(profile实现shoppingcart) 转..
- ssd3: Exercise 1 Shopping Cart Application
- Bigcommerce系统:shopping cart的“购买数量”文本框,change事件改为keyup事件
- iOS 6 编程--Core Data持久化数据存储(2)-使用Core Data实现简单ShoppingCart应用程序