我正在应用一个:after
伪元素到body上,显示我的媒体查询断点的名称,如下所示:
body::after {
content: 'medium';
display: none;
}
这样做的原因可以在这里找到: http://adactio.com/journal/5429/
我想在IE8中使用JavaScript获取:after
的内容值。
这是我为其他浏览器做的方式:
var breakpoint = window.getComputedStyle(document.body, ':after').getPropertyValue('content');
但是IE8不支持getComputedStyle()
,我知道它支持currentStyle
,但是经过一番尝试,我无法正确使用它。
以下是我尝试但没有成功的事情:
var breakpoint = document.body.currentStyle.getPropertyValue('content');
有人知道如何做到这一点吗?
编辑:在BoltClock的提示之后,我现在将我的CSS更改为以下内容(只有一个分号):
body:after {
content: 'medium';
display: none;
}
在使用two之前,内容甚至无法在IE8中显示,因此它没有任何返回值。不幸的是,我仍然无法让IE8返回内容。
我正在尝试这个:
if (style = document.body.currentStyle) {
for (var prop in style) {
if (prop === 'content') {
alert(prop);
}
}
}
我什么都没得到,但如果我将
'content'
更改为其他属性,如'backgroundColor'
,它会弹出一些内容。因此,我认为即使msdn将content列为currentStyle
的可用属性之一http://msdn.microsoft.com/en-us/library/ie/ms535231%28v=vs.85%29.aspx,除非我做错了其他事情,否则它实际上不会返回它。
::after
。如果需要支持IE8,请使用:after
。 - BoltClock