Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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 JS window.answer在另一个html页面上未定义_Javascript_Html_Window_Undefined - Fatal编程技术网

Javascript JS window.answer在另一个html页面上未定义

Javascript JS window.answer在另一个html页面上未定义,javascript,html,window,undefined,Javascript,Html,Window,Undefined,我在一个html页面上计算一些值,并在另一个html页面上报告该值。为了将计算出的答案传递到下一页,我将其存储在window.answer=myValue中,并按位置更改了页面。href=answer.html。在answer.html上,my window.answer未定义。有什么问题吗 function callback() { if (this.id === q[i][0]) { correct++; } else { incorrect++; }; if

我在一个html页面上计算一些值,并在另一个html页面上报告该值。为了将计算出的答案传递到下一页,我将其存储在window.answer=myValue中,并按位置更改了页面。href=answer.html。在answer.html上,my window.answer未定义。有什么问题吗

function callback() {
  if (this.id === q[i][0]) {
    correct++;
  } else {
    incorrect++;
  };
  if (i < q.length - 1) {
    i++;
    document.getElementById('question').innerText = q[i][1];
    document.getElementById('true').setAttribute('aria-valuenow', Math.floor(((correct + incorrect) / q.length) * 100));
    document.getElementById('true').setAttribute('style', "width: " + ((correct + incorrect) / q.length) * 100 + "%");
    document.getElementById('true').innerText = Math.floor(((correct + incorrect) / q.length) * 100);
  } else {
    window.answer = Math.floor(100 * (correct / q.length));
    window.location.href = "answer.html";
  }
}
函数回调(){
if(this.id==q[i][0]){
正确的++;
}否则{
不正确的++;
};
如果(i
导航更改时,窗口对象将刷新。用于在不同页面之间持久化数据

确定答案

window.localStorage.setItem('answer', Math.floor(100 * (correct / q.length)));
关于answer.html

var answer = window.getItem('answer');

备选方案

可能重复的感谢它解决了问题。奇怪的是,我可以将window.name从一个页面转移到另一个页面,但不能转移分数:)