【发布时间】:2012-01-03 22:25:10
【问题描述】:
我有一个很奇怪的问题要解决;解决方案应该是纯 JavaScript(不允许使用框架)。这里是:“显示页面上启用的所有样式表”。
我使用 chrome 是因为 IE 中存在多个 innerHtml 问题,尽管它具有样式表的 cssText 属性,非常适合我的目的。
不管怎样,这是我的例子
<html>
<head>
<style MEDIA="screen">
h1 {color:blue; font-size:10pt; background-color:cyan}
</style>
<style MEDIA="screen" DISABLED="true">
h4 {color:blue; font-size:10pt; background-color:cyan}
</style>
<style MEDIA="print">
h1 {color:gray; font-size:12pt; font-weight: bold}
h2 {font-style:italic}
</style>
<style DISABLED="true">
h2 {color:green; font-size:12pt}
</style>
<style>
h3 {font-style:italic}
</style>
<script language="Javascript">
function displayActiveStyles() {
var container = document.getElementById('activeStyles');
var i;
for (i=0; i<document.styleSheets.length; i++) {
alert(document.styleSheets[i].disabled);
}
}
</script>
</head>
<body>
<h1>one</h1>
<h2>two</h2>
<h3>three</h3>
<input type="button" value="show" onclick="displayActiveStyles()" >
<hr />
<div id="activeStyles"></div>
</body>
</html>
问题是,对于所有 5 个样式表,它都会警告 false 这是不正确的。如果有人知道我在哪里犯了错误,或者在 chrome 中是否可行,请告诉我。
【问题讨论】:
-
您的语言和用户名...有点冲突 ;)
-
chromium 报告了一个错误code.google.com/p/chromium/issues/detail?id=88310。 Google 正在使用 chromium 源来构建他们的 Google Chrome 浏览器
-
Blender, =) 好点子,用“废话”代替废话可以吗?
标签: javascript css google-chrome stylesheet