博主信息
博文 22
粉丝 0
评论 1
访问量 22708
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
JavaScript控制DIV样式
刘静的博客
原创
973人浏览过

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>
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学