Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 本地存储无法与_Javascript_Local Storage - Fatal编程技术网

Javascript 本地存储无法与

Javascript 本地存储无法与,javascript,local-storage,Javascript,Local Storage,我目前正在尝试用javascript制作一些东西,你可以看到我用javascript制作了一个剧场大厅 我制作了一个包含表内数据的大表,其中包含由loopu生成的Id,您可以在函数tekenZaal1中的if/else下看到该Id。 现在,如果你按下加载按钮,我希望选中按下的复选框将被添加到本地存储 我尝试了一些,但它不起作用,它只向本地存储添加了1个字符串 关键字:未定义 和 值:未定义。 我不知道如何解决这个问题我的代码怎么了? 顺便说一句:我无法让JSFIDLE使用我的代码idk为什么,但

我目前正在尝试用javascript制作一些东西,你可以看到我用javascript制作了一个剧场大厅

我制作了一个包含表内数据的大表,其中包含由loopu生成的Id,您可以在函数tekenZaal1中的if/else下看到该Id。 现在,如果你按下加载按钮,我希望选中按下的复选框将被添加到本地存储

我尝试了一些,但它不起作用,它只向本地存储添加了1个字符串 关键字:未定义 和 值:未定义。 我不知道如何解决这个问题我的代码怎么了? 顺便说一句:我无法让JSFIDLE使用我的代码idk为什么,但我有一个屏幕截图,显示了我在theather hall的完整html和javascript代码:

HTML:

javascript:

var zaal1 = 
[ //Array van zaal1//
[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0],
[0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,0,0,0],
[0,0,0,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,0,0,0],
[0,0,0,1,1,1,1,1,2,2,2,2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,0,0]
];

//Variabelen die worden weergegeven in de <p> die aangemaakt wordt als je op een stoel klikt//


//functie die zaal1 tekent//
function tekenZaal1()
 { 

var zaal = "";

     zaal+="<table border='0' id='tabel'>";

for(i = 0; i < zaal1.length; i++){

    zaal+='<tr>';

   for (j = 0; j < zaal1[i].length; j++){


    if (zaal1[i][j] == 1){ 
         zaal+='<td class="prijslaag"><input title="rij'+(i+1)+'stoel'+j+'" type="checkbox" class="stoel1" id="rij'+i+'stoel'+j+'" name="choice" value="7,50" onchange="bereken(1 , checked, Blauw)"></td>';
    }
    else if  (zaal1[i][j] == 2){
         zaal+='<td class="prijsmiddel"><input title="rij'+(i+1)+'stoel'+j+'" type="checkbox" class="stoel2" id="rij'+i+'stoel'+j+'" name="choice" value="9" onchange="bereken(2, checked, Oranje)"></td>';
    }
    else if  (zaal1[i][j] == 3){
        zaal+='<td class="prijshoog"><input title="rij'+(i+1)+'stoel'+j+'" type="checkbox" class="stoel3 "id="rij'+i+'stoel'+j+'" name="choice" value="11" onchange="bereken(3 , checked, Rood)"></td>';
    } 
    else {
         zaal+='<td><img src="witlogo.png" width="40" height="40"></td>';
    } 

}

       zaal+="</tr>";
    } 

       zaal+="</table><br>";

        document.getElementById("content").innerHTML+= zaal;
} 
function bereken(type, checked, kleur) {


if (checked) {
    if (type == 1) {
    prijs += 7.50;
    }
    else if (type == 2) {
    prijs += 9;
    }
    else if (type == 3) {
    prijs += 11;
    }
    //Maakt een <p> en zet daar de aangeklikte stoel in//
    var para = document.createElement('p');
    para.id = ('stoel'+ type);
    var node = document.createTextNode(kleur);
    para.appendChild(node);
    var element = document.getElementById("content1");
        element.appendChild(para);
}
else {
    if (type == 1) {
    prijs -= 7.50;  
    }

    else if (type == 2) {
    prijs -= 9;

    }
    else if (type == 3) {
    prijs -= 11;

    }
    // Verwijderd de desbetreffende <p>stoel die is aangemaakt//
    para = document.getElementById('stoel'+type);
        para.parentElement.removeChild(para);

}

document.getElementById("content2").innerHTML = "<p id='prijstotaal'>\u20ac"+" "+prijs+"</p>";

}

function addStorage() {
    var stoelen = ['rij'+i+"stoel"+j+""]
    var zaal = ['zaal1', 'zaal2', 'zaal3']

        if ("localStorage" in window) {
            localStorage.setItem(stoelen.value, zaal.value);
            alert("localstorage set");
        }
        else {
            alert("no localStorage in window");
        }
}

您希望zaal.value做什么?从var zaal获取值。但是我想我犯了一个很大的错误therezaal.value==未定义。zaal没有属性值…你能更具体一点吗?你说var zaal的值是什么意思?我认为在本地存储中,你需要一个键和一个值,我认为zaal.value现在不能工作,但我不知道如何正确使用它
var zaal1 = 
[ //Array van zaal1//
[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0],
[0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,0,0,0],
[0,0,0,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,0,0,0],
[0,0,0,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,0,0,0],
[0,0,0,1,1,1,1,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,1,1,1,1,0,0,0],
[0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1,0,0],
[0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1,0],
[0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1,0],
[0,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,3,3,2,2,2,2,2,2,1,1,1,1,0],
[0,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,3,3,2,2,2,2,2,2,1,1,1,1,0],
[0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1,0],
[0,1,1,1,1,1,1,2,2,2,2,3,3,3,3,3,3,3,3,2,2,2,2,1,1,1,1,1,1,0],
[0,1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,2,2,2,2,2,1,1,1,1,1,1,1,0],
[0,0,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,0,0],
[0,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,0,0],
[0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,0,0,0],
[0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,0,0,0],
[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0],
[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0]
];

//Variabelen die worden weergegeven in de <p> die aangemaakt wordt als je op een stoel klikt//


//functie die zaal1 tekent//
function tekenZaal1()
 { 

var zaal = "";

     zaal+="<table border='0' id='tabel'>";

for(i = 0; i < zaal1.length; i++){

    zaal+='<tr>';

   for (j = 0; j < zaal1[i].length; j++){


    if (zaal1[i][j] == 1){ 
         zaal+='<td class="prijslaag"><input title="rij'+(i+1)+'stoel'+j+'" type="checkbox" class="stoel1" id="rij'+i+'stoel'+j+'" name="choice" value="7,50" onchange="bereken(1 , checked, Blauw)"></td>';
    }
    else if  (zaal1[i][j] == 2){
         zaal+='<td class="prijsmiddel"><input title="rij'+(i+1)+'stoel'+j+'" type="checkbox" class="stoel2" id="rij'+i+'stoel'+j+'" name="choice" value="9" onchange="bereken(2, checked, Oranje)"></td>';
    }
    else if  (zaal1[i][j] == 3){
        zaal+='<td class="prijshoog"><input title="rij'+(i+1)+'stoel'+j+'" type="checkbox" class="stoel3 "id="rij'+i+'stoel'+j+'" name="choice" value="11" onchange="bereken(3 , checked, Rood)"></td>';
    } 
    else {
         zaal+='<td><img src="witlogo.png" width="40" height="40"></td>';
    } 

}

       zaal+="</tr>";
    } 

       zaal+="</table><br>";

        document.getElementById("content").innerHTML+= zaal;
} 
function bereken(type, checked, kleur) {


if (checked) {
    if (type == 1) {
    prijs += 7.50;
    }
    else if (type == 2) {
    prijs += 9;
    }
    else if (type == 3) {
    prijs += 11;
    }
    //Maakt een <p> en zet daar de aangeklikte stoel in//
    var para = document.createElement('p');
    para.id = ('stoel'+ type);
    var node = document.createTextNode(kleur);
    para.appendChild(node);
    var element = document.getElementById("content1");
        element.appendChild(para);
}
else {
    if (type == 1) {
    prijs -= 7.50;  
    }

    else if (type == 2) {
    prijs -= 9;

    }
    else if (type == 3) {
    prijs -= 11;

    }
    // Verwijderd de desbetreffende <p>stoel die is aangemaakt//
    para = document.getElementById('stoel'+type);
        para.parentElement.removeChild(para);

}

document.getElementById("content2").innerHTML = "<p id='prijstotaal'>\u20ac"+" "+prijs+"</p>";

}

function addStorage() {
    var stoelen = ['rij'+i+"stoel"+j+""]
    var zaal = ['zaal1', 'zaal2', 'zaal3']

        if ("localStorage" in window) {
            localStorage.setItem(stoelen.value, zaal.value);
            alert("localstorage set");
        }
        else {
            alert("no localStorage in window");
        }
}