Home > front end >  Have more than one commodity HTML pages, but only a shopping cart page, how can in a different page
Have more than one commodity HTML pages, but only a shopping cart page, how can in a different page

Time:10-08

There are several different HTML file, the goods inside has an add to cart button, each page to view the shopping cart inside the add content at any time, click on these buttons in different pages how to make these goods to join the shopping cart page? (just like taobao effect, regardless of which goods into the interface, everything in the shopping cart) for bosses

CodePudding user response:

Create a new empty array newArr inside the sessionStorage, each time you click on add insert a, of the same id number + 1

Var newArr=[{
Id: "001",
Num: 2
}];


The shopping cart page access newArr

, of course, this is just a front end operations, if clear the cache won't get it, it is best to use a backend interface for storing and retrieving

CodePudding user response:

LocalStorage to read data

CodePudding user response:

Set up shopping cart object, this kind of circumstance can consider to use the singleton pattern
  • Related