JS使用getComputedStyle()方法获取CSS属性值
2017-06-15 15:18
549 查看
<span style="font-family:Arial;font-size:14px;"><!DOCTYPE html> <html> <head> <title>计算元素样式</title> <style> #myDiv { background-color:blue; width:100px; height:200px; } </style> <body> <div id ="myDiv" style="background-color:red; border:1px solid black"></div> <script> var myDiv = document.getElementById("myDiv"); var computedStyle = document.defaultView.getComputedStyle(myDiv, null); alert(computedStyle.backgroundColor); //"red" alert(computedStyle.width); //"100px" alert(computedStyle.height); //"200px" alert(computedStyle.border); //在某些浏览器中是“1px solid black” </script> </body> </head> </html></span>IE中使用的是obj.currentStyle方法,而FF是用的是getComputedStyle 方法
相关文章推荐
- JS使用getComputedStyle()方法获取CSS属性值
- JS使用getComputedStyle()方法获取CSS属性值
- JS基础篇--JS中使用document.defaultView.getComputedStyle()、currentStyle()方法获取CSS属性值
- JS使用getComputedStyle()方法获取CSS属性值
- JS获取CSS属性值:getComputedStyle()
- js获取css值的方法:style、getComputedStyle和currentStyle
- 获取CSS属性值的方法getComputedStyle
- js获取css值的方法:style、getComputedStyle和currentStyle
- js获取css值的方法:style、getComputedStyle和currentStyle
- 学习——获取元素css值之getComputedStyle方法熟悉
- 转贴:获取元素CSS值之getComputedStyle方法熟悉
- 如何用js获取元素样式(get.ComputedStyle()和currentStyle方法)
- JS获取元素属性、样式getComputedStyle()和currentStyle方法兼容性问题
- 获取元素CSS值之getComputedStyle方法熟悉
- 获取元素CSS值之getComputedStyle方法熟悉
- 转载一篇张鑫旭大大的文章,我感觉不错!!【获取元素CSS值之getComputedStyle方法熟悉】
- 获取元素CSS值之getComputedStyle方法熟悉
- 获取元素CSS值之getComputedStyle方法熟悉
- Javascript获取CSS属性值getComputedStyle和currentStyle
- Javascript获取CSS属性值getComputedStyle和currentStyle