我设了个全局变量vary=node1.length;但是在abc()里不认y。写成y=3就认;为什么?代码:<!DOCTYPEhtmlPUBLIC“-//W3C//DTD... 我设了个全局变量var y=node1.length;但是在abc()里不认y。写成y=3就认;为什么?
代码:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “ http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd “>
<html>
<head>
<script src=" http://libs.baidu.com/jquery/1.8.2/jquery.js " type="text/javascript"></script>
<style>
.a02{;}
.ul01{margin:0 10px 0 0;padding:0;list-style:none;position:relative;right:0px;top:-30px;float:right;}
li{float:right;margin-left:5px;}
.a01{display:block;background:#ccc;width:20px;height:20px;text-align:center;text-decoration:none;}
.a01:hover,.a01:focus,.a01:active{background:#c22;}
.div01{height:2000px;}
.div01 div{width:1000px;height:1000px;border:2px solid #f00;position:relative;left:100px;top:100px;overflow:hidden;}
img{display:block;width:1000px;height:800px;}
</style>
<script>
var x=0;var time;

$(function(){
var node1=$("#div02").children("a");var y=node1.length;
alert($y);
$("#div02").children(":eq(0)").show();
$("#div02").append("<ul class='ul01'></ul>");
for(var i=y;i>0;i--){
$(".ul01").append("<li><a class='a01' href='javascript:bannermenu("+i+");'>"+i+"</a></li>");
}
time=setInterval("abc()",3000);
$(".a01").each(function(index)
{
$(".a01:eq("+index+")").mouseover(function(){x=y-index-1;abc();clearInterval(time);});
$(".a01:eq("+index+")").mouseout(function(){time=setInterval("abc()",3000);});
})
})
function abc()
{
for(var i=0;i<y;i++){
if(i!=x)
{$("#div02").children("a:eq("+i+")").hide();
$(".a01:eq("+(y-i-1)+")").css({"background":"#ccc"});
}
else
{$("#div02").children("a:eq("+i+")").show();
$(".a01:eq("+(y-i-1)+")").css({"background":"#c22"});
}
}
if(x<(y-1)){x=x+1;}
else{x=0;}
}
</script>
</head>
<body>
<div class="div01">
<div id="div02"><a href="#" class="a02"><img src="img01.jpg"></a><a href="#" class="a02"><img src="img02.jpg"></a><a href="#" class="a02"><img src="img03.jpg"></a></div>
</div>
</body>
</html>