const good_render = id => {
localStorage.setItem("name", (goods[id].name));
localStorage.setItem("price", (goods[id].price));
localStorage.setItem("img", (goods[id].img))};
< /code>
Я применяю эти значения таким образом: < /p>
document.getElementById("name").textContent = name = localStorage.getItem("name");
document.getElementById("price").textContent = price = localStorage.getItem("price");
document.getElementById("img").src = img = localStorage.getItem("img")
Он прекрасно работает с .textContend, однако с .src — нет. В чем может быть проблема?
=Update=
Коротко: для перехода на страницу продукта необходимо нажать кнопку
Document
good 1
good 2
< /code>
сама страница продукта < /p>
Document
document.getElementById("name").textContent = name = localStorage.getItem("name");
document.getElementById("price").textContent = price = localStorage.getItem("price");
document.getElementById("img").src = img = localStorage.getItem("img")
И исполняемый JS
var goods = {
"good1" : {
"name" : "good1",
"price": 100,
"img" : "https://static.winestreet.ru/off-line/g ... file_S.jpg",
"in_store": 1,
},
"good2" : {
"name" : "good2",
"price": 50,
"img" : "https://pitersmoke.ru/wa-data/public/sh ... 50.970.jpg",
"in_store": 1,
}
};
document.onclick = event => {
if (event.target.id == 'good1') {
good_render(event.target.id);
}
if (event.target.id == 'good2') {
good_render(event.target.id);
}
};
const good_render = id => {
localStorage.setItem("name", (goods[id].name));
localStorage.setItem("price", (goods[id].price));
const imgURL = URL.createObjectURL(goods[id].img);
localStorage.setItem("img", imgURL);
};
Подробнее здесь: https://stackoverflow.com/questions/764 ... th-img-tag
Мобильная версия