JS getComputedStyle()方法

getComputedStyle()方法

JavaScript window对象中的getComputedStyle()方法,接收一个HTML元素作为参数(参数的传递方法可参考下方的实例),返回一个包含该元素的样式信息的object对象。


语法

window.getComputedStyle( HTMLelement )

getComputedStyle()实例代码,及在线编辑器

<p id='p1'>这是一个段落</p>


<style>
  #p1{color:skyblue;font-size:2.5em;}
</style>

<script>
  var p = document.getElementById("p1");
  var style = window.getComputedStyle(p)
  alert(style[0])
</script>

全栈前端 / JavaScript语法 :





















Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.