English 中文(简体)
未标记的參考引用错误: 横跨阵列未定义
原标题:Uncaught ReferenceError: spanArray is not defined
  • 时间:2012-05-22 04:36:58
  •  标签:
  • javascript

我想做一个按钮来启动点击,让随机数字继续运行,(使用)

  1. or 2. to call) but if I press it , the error message shows that "Uncaught

引用错误: 横线阵列没有定义”但数字上方仍在运行, 我无法

了解哪里是错误的地方。

但是如果我用3个,它正常工作。

恶心! Thx!

我3岁时尝试的全代码是 http://jsfiddle.net/eVyjC/

function computeRandom(){
// skip code: have used loop to create six spans already
var spanArray = document.getElementsByTagName("span");
//1.document.write("<input type =  button  value =  start  onclick = "passKeepMove(value,spanArray) "  name = button1>");
//2.document.write("<input type =  button  value =  start  onclick =  "setInterval(function(){keepMove(value,spanArray);}, 10) "  name = button1>");
//3.setInterval(function(){keepMove(value,spanArray);}, 10) ;
   }


function keepMove(val,sp){//call by pointer 

    var index = parseInt(Math.random()*43);//set a increment to avoid repeatition

    for( i = 0; i < sp.length; i++){
    sp[i].innerHTML = val[i+index];
    }
}


function passKeepMove(v,s){
    setInterval(function(){keepMove(v, s);}, 10);
}
最佳回答

>var var sprayArray 前面的 spanArray 正在将 spanArray 变成本地变量。 因此您无法在 computeRandom 函数范围之外访问它 。

您需要将其全球化或设计得更好, 这样您就不需要全球变量 。

问题回答

暂无回答




相关问题
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.

热门标签