一个按钮控制一个div的展开收起,需要用定时器,不知道下面的代码错在哪里


<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>无标题文档</title>

<style>

#cb{ width:1200px; height:20px; border:3px solid rgba(0,204,255,1);

     border-radius:10px; background-image:url(1.jpg) }


</style>

</head>


<body>

<input type="button" value="展开" onClick="aa()" id="cn">

<div id="cb"></div>

<script>

 var cn=document.getElementById("cn");

 var  h=0;

function a(){

if(h<720)

{ h=h+10;

document.getElementById("cb").style.height=h+"px";

cn.value="收起";

}

else{

return

}

setTimeout(a,10);}

function b(){

if(h>20){

h=h-20;

document.getElementById("cb").style.height=h+"px";

cn.value="展开";

}

else{

return

}

setTimeout(a,10)

}

/**/function aa(){

//t=setInterval(time,50);

a();

b();

}

</script>


</body>

</html>


Echo_Chien
浏览 1352回答 1
1回答

刚毅87

b函数中定时器setTimeout(a,10),写错了改为setTimeout(b,10)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript