如何以编程方式访问到一个样式表中的WebKit引擎(Chrome浏览器/ Safari浏览器)

StackOverflow https://stackoverflow.com/questions/560314

在IE通过document.getElementById( “css_id”)。的styleSheet

或在Firefox的document.getElementById( “css_id”)。片

我有一个样式表对象来操作,但在铬和Safari 浏览器特性不存在。

我怎样才能得到那个对象?

由于

有帮助吗?

解决方案

Errr,在我的测试.sheet工作正常 - 我的测试用例是

<html>
<head>
    <style id="styleElement"></style>
    <link id="linkElement" data="data:text/css," rel="stylesheet"></link>
    <script>
        window.onload=function() {
            alert(["<style element>.style: " + document.getElementById('styleElement').sheet,
                   "<link element>.style: " + document.getElementById('linkElement').sheet])
        }
    </script>
</head>
</html>

我只在Safari 3.2测试和,WebKit Nightlies版,Chrome现在使用WebKit在Safari浏览器3.1,但我不相信有3.1和3.2之间的任何发动机的变化。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top