幾行代碼輕松實現(xiàn)PHP文件打包下載zip
805
2024-01-10
本文實例講述了jQuery基于cookie實現(xiàn)的購物車。分享給大家供大家參考,具體如下:
這里分析了jquery購物車原理,包括添加商品及數(shù)量到購物車 cookie 中,判斷購物車中有無商品,如果有,則把json字符串轉(zhuǎn)換成對象,返回當前商品在 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è)計有所幫助。
#免責(zé)聲明#
本站[綠夏技術(shù)導(dǎo)航]提供的一切軟件、教程和內(nèi)容信息僅限用于學(xué)習(xí)和研究目的;不得將上述內(nèi)容用于商業(yè)或者非法用途,否則,一切后果請用戶自負。本站信息來自網(wǎng)絡(luò)收集整理,版權(quán)爭議與本站無關(guān)。您必須在下載后的24個小時之內(nèi),從您的電腦或手機中徹底刪除上述內(nèi)容。如果您喜歡該程序或內(nèi)容,請支持正版,購買注冊,得到更好的正版服務(wù)。我們非常重視版權(quán)問題,如有侵權(quán)請郵件[admin@lxwl520.com]與我們聯(lián)系進行刪除處理。敬請諒解!