怎么取不到.currentStyle.content的值

天际的海浪 2013-03-18 04:31:13
怎么取不到.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>
...全文
279 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jswatcher 2013-03-19
  • 打赏
  • 举报
回复
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). 才有可能。
天际的海浪 2013-03-19
  • 打赏
  • 举报
回复
IE8就用自定义的属性好了 哎,同一样式又要写两份。。。。。。。(咦,为什么要说“又”)
天际的海浪 2013-03-18
  • 打赏
  • 举报
回复
非ie的用getComputedStyle(d,false).content就可以取得 currentStyle.content怎么就不行啊

<!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 { 
	color: #ff0000;
	content: 'asdf';
} 
</style>
</head>
<body>
<div class="m">777</div>
<script type="text/javascript">
var d = document.querySelectorAll(".m")[0];
if(d.currentStyle)
	alert(d.currentStyle.content);
else
	alert(window.getComputedStyle(d,false).content);
</script>
</body>
</html>
还有currentStyle.content属性在ie中是不是有别的作用 因为currentStyle连用户自定义的属性都能取得。

87,917

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧