为什么我的局部变量没有引用,但是还是一样运行,难道事件会自动传变量吗
// JavaScript Document
var data=['iPhone5','50元充值卡','100元超市购物卷','数码相机','谢谢参与!','笔记本电脑','笔记本','SB称号','抽个毛线'];
var timer=null;
var flag=0;
window.onload=function()
{
var title=document.getElementById('title'),
begin=document.getElementById('begin'),
stop1=document.getElementById('stop');
begin.onclick=begindraw;
stop1.onclick=stopdraw;
document.onkeydown=function(e){
e=e||window.event;
if(e.keyCode==13){
if(flag==0){
begindraw();
flag=1;
}else{
stopdraw();
flag=0;
}
}
}
}
function begindraw()
{
clearInterval(timer);
timer=setInterval(bdraw,50);
begin.style.background="#999";
}
function bdraw()
{
var random1=Math.floor(Math.random()*data.length);
//console.log(random1);
title.innerHTML=data[random1];
}
function stopdraw(){
clearInterval(timer);
begin.style.background="#00C";
}我在begindraw里,stopdraw里都没有引入onload中的变量,结果还是一样运行了。