我当前正在sessionStorage中的单选按钮中存储选定的值,然后在另一页的表中输出它们。这在Chrome中运行良好,但我无法在IE或Firefox中使用它。有谁知道可能导致这种差异的原因是什么?
使用代码更新
HTML调用
var basket = sessionStorage.bask;
if(basket){
basket=JSON.parse(basket);
if(_.size(basket)) content = toTable(basket);
Javascript函数
function Basket(){
var css = 'input#size[name="toy"]:checked';
var input = document.querySelector(css);
var size = input.value==='1'?'small':'large';
var price = Number(input.getAttribute('data-price'));
var orderline = [this.name,size,price];
addToBasket(orderline);
document.getElementById("content").innerHTML="order" + sessionStorage.bask;
}
function addToBasket(item){
var basket=sessionStorage.bask;
if(basket){
basket=JSON.parse(basket);
}else{
basket=new Object();
}
var name = nextName(basket);
basket[name]=item;
sessionStorage.bask=JSON.stringify(basket,null,'\t');
}
function toTable(basket){
var count = 0;
var str = '<table id="basket" border="1" cellspacing="5" cellpadding="5">';
for (var key in basket){
str+= '<tr id="body" class="">';
str+= '<td>'+basket[key].[0]+'</td>';
str+= '<td>'+basket[key].[1]+'</td>';
str+= '<td>£'+basket[key].[2]+'</td></tr>';
}
str+= '<tr><td colspan="3"> Total Price£'+getPrice(basket).toFixed(2)+'</td></tr>';
return str+'<table/>';
}