Blogger Information
Blog 22
fans 0
comment 1
visits 17869
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JavaScript控制DIV样式
刘静的博客
Original
754 people have browsed it

JavaScript控制DIV样式代码如下:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>01.JavaScript控制DIV样式</title>
  6. <style type="text/css" media="screen">
  7. #box{width:100px;height:100px;background:red;margin:20px 80px;}
  8. </style>
  9. </head>
  10. <body>
  11. <div id="box">
  12. </div>
  13. <input type="button" value="变高" onclick="aa(this)">
  14. <input type="button" value="变宽" onclick="bb(this)">
  15. <input type="button" value="变色" onclick="cc(this)">
  16. <input type="button" value="重置" onclick="dd(this)">
  17. <input type="button" value="隐藏" onclick="ee(this)">
  18. <input type="button" value="显示" onclick="ff(this)">
  19. <script type="text/javascript">
  20. var box;
  21. window.onload=function(){
  22. box=document.getElementById('box')
  23. }
  24. function aa(){
  25. box.style.height="400px";
  26. }
  27. function bb(){
  28. box.style.width="400px";
  29. }
  30. function cc(){
  31. box.style.background="blue";
  32. }
  33. function dd(){
  34. box.style.height="100px";
  35. box.style.width="100px";
  36. box.style.background="red";
  37. }
  38. function ee(){
  39. box.style.display="none";
  40. }
  41. function ff(){
  42. box.style.display="block";
  43. }
  44. </script>
  45. </body>
  46. </html>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!