Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.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_Html_Innerhtml_Getelementbyid - Fatal编程技术网

Javascript 为什么我的代码有时返回未定义的

Javascript 为什么我的代码有时返回未定义的,javascript,html,innerhtml,getelementbyid,Javascript,Html,Innerhtml,Getelementbyid,我试图显示两个不同的数字,但每次结果都是相同的,有时显示未定义的。有办法解决这个问题吗 var usedCard=[0]; var columnB=Math.floor(Math.random()*16); 函数columnb(){ 如果(使用卡片包括(B列)){ columnB=Math.floor(Math.random()*16); 柱状体b(); } else{return columnB}; } document.getElementById(“B1”).innerHTML=colu

我试图显示两个不同的数字,但每次结果都是相同的,有时显示未定义的。有办法解决这个问题吗

var usedCard=[0];
var columnB=Math.floor(Math.random()*16);
函数columnb(){
如果(使用卡片包括(B列)){
columnB=Math.floor(Math.random()*16);
柱状体b();
}
else{return columnB};
}
document.getElementById(“B1”).innerHTML=columnBB();
使用卡片推送(B列);
columnB=Math.floor(Math.random()*16)
document.getElementById(“B2”).innerHTML=columnBB()

您正在使用递归。当函数调用自身时,它永远不会返回,因为只有在从未调用if分支的情况下,它才会调用else分支。除去else,然后简单地返回,你应该是好的

var usedCard=[0];
var columnB=Math.floor(Math.random()*16);
函数columnb(){
如果(使用卡片包括(B列)){
columnB=Math.floor(Math.random()*16);
柱状体b();
}
返回栏B;
}
document.getElementById(“B1”).innerHTML=columnBB();
使用卡片推送(B列);
columnB=Math.floor(Math.random()*16)
document.getElementById(“B2”).innerHTML=columnBB()

多次运行代码段