首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

如何取不到.currentStyle.content的值

2013-03-20 
怎么取不到.currentStyle.content的值本帖最后由 jslang 于 2013-03-18 16:33:36 编辑怎么取不到.currentS

怎么取不到.currentStyle.content的值
本帖最后由 jslang 于 2013-03-18 16:33:36 编辑 怎么取不到.currentStyle.content的值,我是ie8


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<style type="text/css">
.m:before { content: "asdf"; } 
.m { color: #ff0000; } 
</style>
</head>
<body>
<div class="m">777</div>
<script type="text/javascript">
alert(document.querySelectorAll(".m")[0].currentStyle.content);
</script>
</body>
</html>

[解决办法]
In IE8, it is a mission impossible.

在 IE8, 这大概是不可能的。因为,content 是用来定义 pseudo elements (比如,:before, :after).
currentStyle, 是一般 DOM element 的属性,不能用于pseudo elements。
首先,你就无法得到 pseudo elements (比如说用 getElementById)

到了 IE9,微软也引入支持getComputedStyle(element, pseudo). 才有可能。

热点排行
Bad Request.