zoukankan      html  css  js  c++  java
  • getComputedStyle获取元素样式值

    html:

        <style>
          .div {
            width: 200px;
            height: 200px;
            background-color: greenyellow;
          }
        </style>
      </head>
      <body>
        <div class="div">一些文字</div>
        <script>
          const div = document.getElementsByClassName('div')[0]
          const style = getComputedStyle(div)
          console.log(style)
          console.log(style.backgroundColor) // rgb(173, 255, 47)
        </script>
      </body>

    vue:

      mounted() {
        const ref = this.$refs.h1Ref
        const style = getComputedStyle(ref)
        console.log(style)
        console.log(style.color)
        ref.classList.add('aa')
      }
  • 相关阅读:
    HTML区块
    HTML表单
    JavaScript 表单验证
    HTML头部
    JavaScript
    设计模式—单例模式的六种写法
    new
    new
    new
    new
  • 原文地址:https://www.cnblogs.com/wuqilang/p/15332741.html
Copyright © 2011-2022 走看看