本文实例讲述了jquery基于cookie实现的购物车。分享给大家供大家参考,具体如下:
这里分析了jquery购物车原理,包括添加商品及数量到购物车 cookie 中,判断购物车中有无商品,如果有,则把json字符串转换成对象,返回当前商品在 cookie 中的总数。
将商品放入购物车:
$(function(){
$(".tc").hide();
var PId = $("#hfPId").val(); // 商品的ID
var PName = $("#lblPName").text(); // 商品名称
var PMemberPrice = $("#lblPMemberPrice").text(); // 会员价
var PAmount = 1;
var jsonStr = "[{'PId':'" + PId + "','PName':'" + PName + "','PMemberPrice':'" + PMemberPrice + "','PAmount':'" + PAmount + "'}]";
//将商品放入购物车
$("#putCart").click(function(){
setCookie(PId, jsonStr);
});
赋值:
项目介绍: eShop是基于eFrameWork低代码开发平台搭建的微信公众号商城系统,主要功能包括:产品、订单、购物车、收藏、收货地址。已集成微信登录、微信支付、分享等接口。更多功能可自行二次开发实现。 当前发布的数据库有两个版本,SQLServer和SQLite(无需安装数据库),默认为SQLite,根据实际需要切换。 项目版本:VS2012+, 数据库版本:S
13
var setCookie = function(name, value, options){
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString();
}
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
希望本文所述对大家jQuery程序设计有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号