欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery基于cookie實(shí)現(xiàn)的購物車實(shí)例分析

 更新時間:2015年12月24日 12:06:26   作者:desteps  
這篇文章主要介紹了jQuery基于cookie實(shí)現(xiàn)購物車的方法,結(jié)合實(shí)例形式簡單分析了jQuery基于cookie實(shí)現(xiàn)針對商品信息的購物車存儲功能,具有一定參考借鑒價值,需要的朋友可以參考下

本文實(shí)例講述了jQuery基于cookie實(shí)現(xiàn)的購物車。分享給大家供大家參考,具體如下:

這里分析了jquery購物車原理,包括添加商品及數(shù)量到購物車 cookie 中,判斷購物車中有無商品,如果有,則把json字符串轉(zhuǎn)換成對象,返回當(dāng)前商品在 cookie 中的總數(shù)。

將商品放入購物車:

$(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);
});

賦值:

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程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論