由于Chrome Stable登陆版本33.0.1750.117,因此window.getComputedStyle的逻辑已从其他浏览器更改.下面的代码小提琴:http://jsfiddle.net/HD4bD/17/
任何人都可以解释变化的内容以及对此的"正确"裁决是什么?
鉴于以下内容:
<body>
<div class="normal"></div>
<div class="display-none"></div>
<div class="visibility-hidden"></div>
</body>
Run Code Online (Sandbox Code Playgroud)
.normal:before {
content: "NORMAL: "
}
.display-none:before {
content: "DISPLAY-NONE: ";
display: none;
}
.visibility-hidden:before {
content: "VIS-HIDDEN: "
visibility: hidden;
}
Run Code Online (Sandbox Code Playgroud)
var $ = document.querySelector.bind(document),
pass = "This text should have 1 or more labels before it",
fail = "The label is missing. Something's wrong.",
normalContent = getB4Content('.normal'),
dNoneContent = getB4Content('.display-none'),
vHideContent = getB4Content('.visibility-hidden');
function getB4Content(selector){
return window.getComputedStyle($(selector),':before').getPropertyValue('content');
} …Run Code Online (Sandbox Code Playgroud)