English 中文(简体)
javascript syntax - 这就是为什么职能不承认一个宣布和填满的外部阵列。
原标题:javascript syntax - why function does not recognize an outside array that is declared and filled

我在下文所述职能中包含各种阵列,用于储存多功能线索,以减少多功能探测器。 它现在就运作了,但我希望在其他职能中再利用这些阵列,因此,我试图将阵列声明和排在职能之外,当职能首次提到行凶者时,功能错误就显现出来,因为这一职能并不被承认。 我的理解是,“过去”将给予范围,但我试图去除/包括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]
.
.
.
}
最佳回答

您也把 lo移到职能之外。 这或许不会奏效,因为这意味着:getElementById。 印本正在装满。 DOM树尚未建成,例如getElementById 回归代码>null。

问题回答

我并不认为它是一个问题,它涉及范围不一,而涉及你的指数。 从这个例子中,我可以列举以下几个例子:>>:目前本应做到,但是,如果 lo在鸡园之前就已经开了,那么,你们的阵列就 empty空了,而指数化将 me。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签