我在下文所述职能中包含各种阵列,用于储存多功能线索,以减少多功能探测器。 它现在就运作了,但我希望在其他职能中再利用这些阵列,因此,我试图将阵列声明和排在职能之外,当职能首次提到行凶者时,功能错误就显现出来,因为这一职能并不被承认。 我的理解是,“过去”将给予范围,但我试图去除/包括var,而且它仍然不起作用。
请解释
TIA
当停机在功能中申报时(被编辑成“ lo”的封闭标记)即可进行。
function display (namearr, current) {
var aarr = [];
var barr = [];
for (var z=1; z<=10; z++) {
c = z-1;
aarr[c] = document.getElementById("a"+z);
barr[c] = document.getElementById("b"+z);
}
var tldstr = document.getElementById("dlist").innerHTML;
tldstr = tldstr.slice(0, -1)
var tldarr = tldstr.split(",");
index = current - 1;
var arrlen = tldarr.length;
var img = "<img src= ../loader1.gif alt= loading width= 40 />";
for (i=0; i<10; i++){
if (index >= arrlen) {
aarr[i].className = "tldn";
barr[i].className = "tldn";
}
else if ( tldarr[index] == "n" || tldarr[index].length != 6)
{
aarr[i].innerHTML = img;
barr[i].innerHTML = img;
}//close first elseif
else {
tldstr = tldarr[index];
aarr[i].className = "tld"+tldstr.charAt(0);
barr[i].className = "tld"+tldstr.charAt(1);
}//close second elseif
index++;
}//close first for loop
}
This does not work (with or without the "var" declaration), function errors out at first encounter of aarr[i]
var aarr = [];
var barr = [];
for (var z=1; z<=10; z++) {
c = z-1;
aarr[c] = document.getElementById("a"+z);
barr[c] = document.getElementById("b"+z);
function display (namearr, current) {
.
.
.
aarr[i].className = "tldn"; //function errors out at first encounter of aarr[i]
.
.
.
}