作者UFOoooooo (宅是一種生活態度)
看板Ajax
標題[ js ] 改變div的大小
時間Thu Jul 24 16:09:47 2008
我希望可以按下div後,div會慢慢的變長
然後還做了一個button,按下後,div會直接回復成原來的樣子
可是一直無法成功
以下是網頁的程式碼
<script language="JavaScript">
<!--
function big1(){
var sizeheight = 100;
for (sizeheight <200; sizeheight += 5;){
return document.getElementById('area1').style.height=sizeheight;
}
}
-->
</script>
<html>
<head>
<title>未命名頁面</title>
<style type="text/css">
.style2 {
border-style: solid;
border-color: black;
background-color: blue;
width: 100px;
height:100px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id=area1 hidefocus="hidefocus" class=style2 onclick=big1()>
</div>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="document.getElementById(area1).style.height='100';"/>
</form>
</body>
</html>
網頁執行之後,按div,div只會變長5px
不知道程式那裡出了問題?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.167.192.211
1F:→ todau:你的迴圈有點無言,用firebug trace你就會發現了.... = = 07/24 17:02
2F:→ UFOoooooo:那請問應該要怎麼改呢? 07/24 17:10
3F:→ adxis:for(var i=0;i<10;i++){...} 07/24 17:31
4F:→ adxis:也不需要return 07/24 17:32
5F:→ adxis:然後 他不會慢慢變長...會瞬間長到回圈跑完的大小 07/24 17:33
6F:→ adxis:要作動畫效果請查 setTimeout 07/24 17:33
7F:推 chph:基本語法要先認識吧.. return 不是這樣用的 07/24 17:33
8F:→ UFOoooooo:謝謝各位,我再試試 07/24 17:36
9F:→ UFOoooooo:我已經試成功了 感謝大家 07/24 17:57