【发布时间】:2020-05-24 14:44:37
【问题描述】:
我正在尝试将此信息存储在本地存储中,但我不希望它覆盖数据,而是希望它附加到我在本地存储中创建的对象中 js代码
function addToCartClicked(event)
{
var button = event.target
var shopItem = button.parentElement.parentElement
var title = shopItem.getElementsByClassName('shop-item-title')[0].innerText
var price = shopItem.getElementsByClassName('shop-item-price')[0].innerText
var imgSrc = shopItem.getElementsByClassName('shop-item-image')[0].src
console.log(title)
addItemToCart(title,price,imgSrc)
}
function addItemToCart(title,price,imgSrc)
{
var product = {
title : title,
price : price,
imgSrc : imgSrc
};
console.log(product)
localStorage.setItem("productsInCart" ,JSON.stringify(product))
}
python 代码
<section class="container content-section">
<h2 class="section-header">On Sale</h2>
<div class="shop-items">
{% for data in product_data %}
<div class="shop-item" >
<span class="shop-item-title" id="title-item">{{ data.title }}</span>
<input type="image" class="shop-item-image" id="image-item" src={{ data["img_file"] }} onclick="takethatpage();">
<div class="shop-item-details">
<span class="shop-item-price" id="price-item">{{ data["price"]}}</span>
<button class="btn btn-primary shop-item-button" type="button">ADD TO CART</button>
</div>
</div>
{% endfor %}
</div>
</section>
【问题讨论】:
标签: javascript python json flask