This is the code when saving
$(".top").click(function(){
var contrastdata = new Object;
contrastdata.Machinedata = $(this).parents('tr').find('td')[0].innerText;
contrastdata.UserNamedata = $(this).parents('tr').find('td')[2].innerText;
contrastdata.InstrumentIDdata = $(this).parents('tr').find('td')[4].innerText;
localStorage.setItem('contrastdata',JSON.stringify(contrastdata));
});
The following is the time to take it
var contrastdata = JSON.parse(localStorage.getItem('contrastdata'));
var Machinedata = contrastdata.Machinedata;
var UserNamedata = contrastdata.UserNamedata;
var InstrumentIDdata = contrastdata.InstrumentIDdata;
Your idea is wrong. You should first take out the original value from LocalStorage, then superimpose the new data into the original value, and then store it in LocalStorage again. This way there will be no data overwriting
Do you want to save different
item
for eachtr
?Overwriting is because the name does not change every time you save it
You can change it to this
var nums = 0;
$(".top").click(function(){
When taking the value below, loop based on the value of nums
or change the data structure, use an object to store data, add the data to the object every time you click, and then store the object in localstroage
First take out the data from localStorage and convert it into an object. Remember to make defensive judgments, then insert the value you want to save into the taken out object, and then convert it into a string and store it in localStorage to overwrite the original data;
Read first, then append, then write.
At the beginning, first assign the value to the variable, and then perform the operation in the click event. The data does not need to be stored directly for the time being. It will be stored when the page jumps or needs to be stored. Otherwise, it will be saved every time it is clicked. Once, and then take it out, it is very troublesome.