如何使用javascript将数组传递给新页面? [英] How to pass an array to a new page using javascript?
本文介绍了如何使用javascript将数组传递给新页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我需要将数组值传递给新的html页面。
i已尝试,但数组值始终重置
hi everyone i need to pass an array value to a new html page. i tried but the array value is always resetting
这是我的代码
var cart=[];
var jumlah=0;
var total=0;
function add(index)
{
if(index==1)
{
jumlah=prompt("masukan jumlah");
if(jumlah==0||jumlah<0||jumlah==null)
{
alert("harap masukkan jumlah, dengan format yang benar");
}
else
{
total=jumlah*500000;
cart.push('Razer Destructor Battlefield @ IDR 500.000|| Jumlah '+jumlah+' || total '+total);
for(var i=0;i<cart.length;i++)
{
alert("barang telah di tambahkan ke keranjang");
}
}
}
else if(index==2)
{
jumlah=prompt("masukan jumlah");
if(jumlah==0||jumlah<0||jumlah==null)
{
alert("harap masukkan jumlah dengan format yang benar");
}
else{
total=jumlah*2020000;
cart.push('Razer blackwidow ultimate mechanical keyboard for gaming @ IDR 2,020,000|| Jumlah '+jumlah+' || total '+total);
alert("barang telah di tambahkan ke keranjang");
}
}}
我需要传递那个cart []数组来自product.html到一个名为cart.html的新页面
i need to pass that cart[] array from product.html to a a new page called cart.html
你能帮助我吗?抱歉,我是初学者,对不起英语不好意思。谢谢你的帮助!
can u guys help me? sorry im a beginner and sorry for bad english. thanks for ur help!!
推荐答案
你应该看看 localStorage
window.localStorage.setItem("cart", JSON.stringify(cart)); // Saving
var cart = JSON.parse(window.localStorage.getItem("cart")); // Retrieving
这篇关于如何使用javascript将数组传递给新页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文