<script>
var products = [
{ id: 0, price: 70000, title: 'Blossom Dress' },
{ id: 1, price: 50000, title: 'Springfield Shirt' },
{ id: 2, price: 60000, title: 'Black Monastery' }
];
products.forEach(function(a, i){
var 탬플릿 = `
<div>
<h5>${products[i].title}</h5>
<p>가격 : ${products[i].price}</p>
<button class="buy">구매</button>
</div>
`
$('.row').append(탬플릿);
});
$('.buy').click(function (e) {
var title = $(e.target).siblings('h5').text();
if (localStorage.getItem('cart') != null) {
var 꺼낸거 = JSON.parse(localStorage.cart);
for (var i = 0; i < 꺼낸거.length; i++) {
if (title != 꺼낸거[i]) {
꺼낸거.push(title);
}
}
localStorage.setItem('cart', JSON.stringify(꺼낸거));
} else {
localStorage.setItem('cart', JSON.stringify([title]))
}
});
</script>
안되는 이유를 모르겠습니다..