Jquery getComputedStyle()在IE8中不工作

Jquery getComputedStyle()在IE8中不工作,jquery,Jquery,我的脚本页面中有getComputedStyle()函数。但它在IE8中不起作用 My code :- var isDesktop = window.getComputedStyle(document.body,':after').getPropertyValue('content'); 错误:- 对象不支持此属性或方法对,getComputedStyle在早期IE中不存在。如果您没有查找伪元素的样式,可以使用ID的currentStyle: var style = documen

我的脚本页面中有getComputedStyle()函数。但它在IE8中不起作用

My code :- 

    var isDesktop = window.getComputedStyle(document.body,':after').getPropertyValue('content');
错误:-
对象不支持此属性或方法

对,
getComputedStyle
在早期IE中不存在。如果您没有查找伪元素的样式,可以使用ID的
currentStyle

var style = document.body.currentStyle || getComputedStyle(document.body);
…(然后使用
样式
上的属性),但IE没有选择伪元素的能力。相反(这很难看),您必须遍历加载的样式表中的样式规则,找出哪些规则适用于所讨论的元素,并从规则的样式中找出伪元素内容

示例:(我会使用堆栈片段,但它们在IE8上不起作用;)


例子
身体{
颜色:蓝色;
}
var style=document.body.currentStyle | | getComputedStyle(document.body);
document.body.insertAdjacentHTML(
“之前”,
颜色:“+style.Color+”

” );

不过,这也不会给出伪元素属性。

这里没有错误。if(isDesktop.indexOf('smallscreen')=-1&&isDeviceMobile()==null){}@kannan:我的答案中没有
isDesktop
。我的答案告诉您如何为元素获取
样式
对象。正如它在回答中所说:“…然后使用
style
..”上的属性,但再一次,您不再试图从伪元素获取它,对吗?style.indexOf('smallscreen')==-1,这里是我得到的对象expected@kannan:什么使你认为
style
是字符串?
getComputedStyle
的返回值是字符串吗?不那么为什么上面的
样式会是?您看过这个实时的工作示例了吗?最新的jquery不支持IE8。
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
  <style>
    body {
      color: blue;
    }
  </style>
</head>
<body>
<script>
  var style = document.body.currentStyle || getComputedStyle(document.body);
  document.body.insertAdjacentHTML(
    "beforeend",
    "<p>Color: " + style.color + "</p>"
  );
  </script>
</body>
</html>