The example in this article is about jquery's cookie-based shopping cart. Share to everyone for your reference, specific as follows:
This article analyzes the jquery shopping cart principles, including adding goods and quantities to the shopping cart cookie, determining if there are any items in the shopping cart, and if so, converting the JSON string into objects and returning the total number of the current item in the cookie.
Put the goods into the shopping cart:
$ (function () {
$ (". TC"). Hide ();
var PId = $ ("#hfPId"). Val (); Product ID
var pname = $ ("#lblPName"). Text ();//commodity name
var pmemberprice = $ ("#lblPMemberPrice"). Text ();//Member Price
V Ar pamount = 1;
var jsonstr = "[{' PID ': '" + pid + "', ' pname ': '" + pname + "', ' pmemberprice ': '" + Pmemberprice + "', ' pamount ': '" + pamount + "'}]";
Put the item in the shopping cart
$ ("#putCart"). Click (function () {
Setcookie (PId, jsonstr);
});
Assign value:
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 * * * * * 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 ': ';
I hope this article will help you with the jquery program design.