日期:2014-05-16  浏览次数:20396 次

请给看段div+js代码
以下网页中有5个div,各显示不同内容
想达到的目标,每一秒显示一个不同的div
问题:为什么我存html里看不到预期效果?
请大手给改下,弄了很长时间了

<head>
<style>
div{ width:100px; height:100px; border:1px solid #000; display:none;}
</style>
</head>
<body>
<div id="div1">div1</div><div id="div2">div2</div><div id="div3">div3</div><div 

id="div4">div4</div><div id="div5">div5</div>

<script>
function change_div(num){
 document.getElementByIdx_x_x("div"+(num-1)).style.display="none";
 if(num==6){
  num=1;
 }
 document.getElementByIdx_x_x("div"+num).style.display="block";
 num++;
 setTimeout("change_div("+num+")",1000);//1秒切换一次
}
change_div(6);
</script>
</body>

------解决方案--------------------
<head>
<style>
div{ width:100px; height:100px; border:1px solid #000; display:none;}
</style>
</head>
<body>
<div id="div1">div1</div><div id="div2">div2</div><div id="div3">div3</div><div

id="div4">div4</div><div id="div5">div5</div>

<script>
function change_div(num){
 document.getElementById("div"+(num-1)).style.display="none";
 if(num==6){
num=1;
 }
 document.getElementById("div"+num).style.display="block";
 num++;
 setTimeout("change_div("+num+")",1000);//1秒切换一次
}
change_div(6);
</script>
</body>
------解决方案--------------------
JScript code
<!DOCTYPE HTML>
<html>
 <head>
<style>
div{ width:100px; height:100px; border:1px solid #000; display:none;}
</style>
</head>
<body>
<div id="div1">div1</div>
<div id="div2">div2</div>
<div id="div3">div3</div>
<div id="div4">div4</div>
<div id="div5">div5</div>

<script>
function change_div(num){
 document.getElementById("div"+(num-1)).style.display="none";
 if(num==6){
  num=1;
 }
 document.getElementById("div"+num).style.display="block";
 num++;
 setTimeout("change_div("+num+")",1000);//1秒切换一次
}
change_div(6);
</script>
</body>
</html>

------解决方案--------------------
getElementById种多了x_x_x,应该是笔误吧