A
A
Artem2020-04-27 19:50:56
JavaScript
Artem, 2020-04-27 19:50:56

How can I individually set attributes to initial value "=0"?

The main array "data" which refers to the json file where all the keys and values ​​.

button class="number" data-num="' + key + '">' + cart[key] + 'button;
button class="plus" data-art="' + key + '" +button;

When you click on the button with the DATA-ART attribute, the value is added, but in the code when everything was just loaded and no one pressed anything at each class=number attribute in the field where "'+key+'" value is "undefined" .
function plus() {
var articul = $(this).attr('data-art');
if (cart[articul]!=undefined) {
cart[articul]++;
}
else{
cart[article] = 1;
}
localStorage. setItem('cart', JSON.stringify(cart));
load Goods();
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question