[ js ] 改變div的大小

看板Ajax作者 (宅是一種生活態度)時間17年前 (2008/07/24 16:09), 編輯推噓1(108)
留言9則, 4人參與, 最新討論串1/1
我希望可以按下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

07/24 17:02, , 1F
你的迴圈有點無言,用firebug trace你就會發現了.... = =
07/24 17:02, 1F

07/24 17:10, , 2F
那請問應該要怎麼改呢?
07/24 17:10, 2F

07/24 17:31, , 3F
for(var i=0;i<10;i++){...}
07/24 17:31, 3F

07/24 17:32, , 4F
也不需要return
07/24 17:32, 4F

07/24 17:33, , 5F
然後 他不會慢慢變長...會瞬間長到回圈跑完的大小
07/24 17:33, 5F

07/24 17:33, , 6F
要作動畫效果請查 setTimeout
07/24 17:33, 6F

07/24 17:33, , 7F
基本語法要先認識吧.. return 不是這樣用的
07/24 17:33, 7F

07/24 17:36, , 8F
謝謝各位,我再試試
07/24 17:36, 8F

07/24 17:57, , 9F
我已經試成功了 感謝大家
07/24 17:57, 9F
文章代碼(AID): #18Y3ZC7N (Ajax)
文章代碼(AID): #18Y3ZC7N (Ajax)