亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

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

將商品放入購(gòu)物車:

$(function(){
$(".tc").hide();
var PId = $("#hfPId").val(); // 商品的ID
var PName = $("#lblPName").text(); // 商品名稱
var PMemberPrice = $("#lblPMemberPrice").text(); // 會(huì)員價(jià)
var PAmount = 1;
var jsonStr = "[{'PId':'" + PId + "','PName':'" + PName + "','PMemberPrice':'" + PMemberPrice + "','PAmount':'" + PAmount + "'}]";
//將商品放入購(gòu)物車
$("#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' : '';

希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論