javascript實現單擊按鈕使div變大效果


    javascript是做效果是很強大的,在沒有學習之前對於很多效果都不知道如何去實現。這是一個簡單的例子,適用於js初學者。下面請看代碼:

 

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml" >
 3 <head>
 4     <title>無標題頁</title>
 5 </head>
 6 <body>
 7 <div id="div1"style="border-style:solid; border-color:Red;width:10px;height:100px;border-widht:1px;">
 8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 </div>
45 <input type="button"  value="放大" onclick="document.getElementById('div1');div1.style.width='200px';div1.style.height='200px';"/>
46 </body>
47 </html>

 這次的javascript代碼是卸載控件的onclick事件中。首先先使用document.getElementById('div1');得到div1。要想使層變大實際上是修改div的樣式中的width和height屬性。所以使用div1.style.width=‘200px’;將div1的寬度修改為200像素,使用div1.style.height='200px';將div1的高度也修改200像素。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM