87,917
社区成员
发帖
与我相关
我的任务
分享
<!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>
<!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连用户自定义的属性都能取得。