jQuery基于cookie實(shí)現(xiàn)的購物車實(shí)例分析
本文實(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(); // 會員價(jià)
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ì)有所幫助。
- jQuery實(shí)現(xiàn)購物車多物品數(shù)量的加減+總價(jià)計(jì)算
- 基于JQuery實(shí)現(xiàn)的類似購物商城的購物車
- 純jquery實(shí)現(xiàn)模仿淘寶購物車結(jié)算
- jQuery實(shí)現(xiàn)購物車數(shù)字加減效果
- jQuery實(shí)現(xiàn)購物車計(jì)算價(jià)格功能的方法
- jQuery實(shí)現(xiàn)類似淘寶購物車全選狀態(tài)示例
- 基于jquery fly插件實(shí)現(xiàn)加入購物車拋物線動畫效果
- jQuery基于json與cookie實(shí)現(xiàn)購物車的方法
- jQuery使用cookie與json簡單實(shí)現(xiàn)購物車功能
- 基于JQuery的購物車添加刪除以及結(jié)算功能示例
相關(guān)文章
HTML5+jQuery實(shí)現(xiàn)搜索智能匹配功能
本文主要介紹了HTML5+jquery實(shí)現(xiàn)的搜索匹配效果的實(shí)例代碼。具有很好的參考價(jià)值。下面跟著小編一起來看下吧2017-03-03
Jquery左右滑動插件之實(shí)現(xiàn)超級炫酷動畫效果附源碼下載
這是一款基于jquery.pogo-slider插件實(shí)現(xiàn)的多個(gè)滑塊切換特效。本篇文章給大家介紹Jquery左右滑動插件之實(shí)現(xiàn)超級炫酷動畫效果,對jquery左右滑動插件相關(guān)知識感興趣的朋友參考下2015-12-12
基于jQuery實(shí)現(xiàn)美觀且實(shí)用的倒計(jì)時(shí)實(shí)例代碼
倒計(jì)時(shí)效果在我們的日常生活中經(jīng)常會用到,比如說高考倒計(jì)時(shí)、元旦放假倒計(jì)時(shí)、春節(jié)放假倒計(jì)時(shí)等等,下面通過本篇文章給大家分享基于jQuery實(shí)現(xiàn)美觀且實(shí)用的倒計(jì)時(shí)實(shí)例代碼,對jquery倒計(jì)時(shí)相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2015-12-12
jQuery仿360導(dǎo)航頁圖標(biāo)拖動排序效果代碼分享
這篇文章主要為大家詳細(xì)介紹了360導(dǎo)航頁圖標(biāo)拖動排序效果代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-08-08
jquery無法設(shè)置checkbox選中即沒有變成選中狀態(tài)
設(shè)置以后checkbox并沒有變成選中狀態(tài),用chrome調(diào)試看了一下,checkbox中確實(shí)有checked屬性,針對這個(gè)問題,大家可以參考下本文2014-03-03
jquery Moblie入門—hello world的示例代碼學(xué)習(xí)
jquery Moblie入門:Hello World的示例代碼學(xué)習(xí),感興趣的朋友可以了解下哦2013-01-01
jQuery實(shí)現(xiàn)圖片與文字描述左右滑動自動切換的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)圖片與文字描述左右滑動自動切換的方法,涉及jquery實(shí)現(xiàn)圖文滑動切換效果的方法,涉及jquery針對頁面元素與樣式的相關(guān)操作技巧,需要的朋友可以參考下2015-07-07

