原生js获取元素的样式
                    根据
MDN介绍:
window.getComputedStyle(elem,null).getPropertyValue("background-color");在ie11下测试不可用,非ie可以,也可以简化:window.getComputedStyle(overlay)["background-color"]效果同上:为了兼容ie:
- function getStyle(element, att){
- //特性侦测
- if(window.getComputedStyle){
- //优先使用W3C规范
- return window.getComputedStyle(element)[att];
- }else{
- //针对IE兼容
- return element.currentStyle[att];
- }
- }
测试元素的background-color为 rgba(0, 0, 0, 0) ,ie9及其他浏览器没有任何问题,ie8返回的是transparent
 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号