操作属性之修改样式属性

ゝ一纸荒年。 2023-10-03 14:27 73阅读 0赞

操作属性之修改样式属性

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>操作属性之修改样式属性</title>
  8. <style>
  9. div {
  10. width: 200px;
  11. height: 200px;
  12. background-color: pink;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div></div>
  18. <script>
  19. // 1. 获取元素
  20. var div = document.querySelector('div');
  21. // 2. 注册事件 处理程序
  22. div.onclick = function () {
  23. // div.style里面的属性 采取
  24. this.style.backgroundColor = 'purple';
  25. this.style.width = '250px';
  26. }
  27. </script>
  28. </body>
  29. </html>

发表评论

表情:
评论列表 (有 0 条评论,73人围观)

还没有评论,来说两句吧...

相关阅读