获取非行内样式的方法
(1) 标准浏览器:getComputedStyle
- 用法:getComputedStyle(要获取样式属性的元素) . 样式属性
(2) Ie8及以下浏览器:currentStyle
- 用法:要获取样式的元素.currentStyle.样式属性
(3) 以上两种方法互相不兼容
(4) 获取非行内样式的方法兼容
//获取任意元素的非行内样式
var getStyle = function(ele,attr){
//1.将主要功能代码写入函数中
if(ele.currentStyle==undefined){
//证明当前浏览器是标准浏览器
var bg = getComputedStyle(ele)[attr];
return bg;
}else{
//否则就是在ie浏览器,就需要使用currentStyle
var bg = ele.currentStyle[attr];
return bg;
}
//2.将不确定的值提出来 做参数 不确定的值就是元素 和 属性
//3.将参数代入函数中
}