获取元素样式

94 阅读1分钟

获取元素样式

*获取元素样式 语法 : 元素.style.某个Css属性 但是只能获取到行内样式

  • 设置元素的样式 语法 : 元素.style.属性 = '属性值' 但是只能设置到行内样式
 //     console.log(oBox.style.background-color) // 错误写法
        console.log(oBox.style['background-color']) // 中括号语法
        console.log(oBox.style.backgroundColor) // 驼峰命名

*获取元素样式( 非行内样式) 注意这种方法获取到的 是只能读取的属性 ,不可以进行修改 语法 : window.getComputedStyle(元素).属性

   console.log( window.getComputedStyle(oBox).backgroundColor)