Add two plug-ins
Jquery. Cookie. js
Jquery. jsoncookie. js
$ (Function (){
VaR wowohistory = $. jsoncookie ("wowohistory"); // read the cookie in JSON format
VaR id = $ ("# selectgoodsid"). Val ();
VaR IMG = $ ("# gooddefimg"). Val ();
VaR name = $ ("# productname"). Text ();
If (typeof (wowohistory. Goods) = "undefined") {// determine whether the cookie exists
Wowohistory = {"goods ":[
{"Goodid": ID, "IMG": IMG, "name": name}]
};
$. Jsoncookie ("wowohistory", wowohistory, {path: '/', expires: 20}); // store Cookie in JSON format
}
Else {
VaR flag = false;
For (VAR I = 0; I <wowohistory. Goods. length; I ++ ){
If (wowohistory. goods [I]. goodid = ID ){
Flag = true; break;
}
}
If (! Flag ){
If (wowohistory. Goods. length> = 10 ){
// Delete wowohistory. goods [0]; // It can only be empty and is not deleted.
Wowohistory. Goods. splice (); // Delete the first row
}
VaR TMP = {"goodid": ID, "IMG": IMG, "name": name };
Wowohistory. Goods. Push (TMP); // Add
$. Jsoncookie ("wowohistory", wowohistory, {path: '/', expires: 20}); // save
}
}
})
Function clearhistory (){
$. Cookie ("wowohistory", null, {path: '/'}); // Delete cookie
$ ("# Wowohistoryshow" ).css ("display", "NONE ");
}