accessingstylesheetsexample5.htm

来自「这是javascript高级程序设计的源码」· HTM 代码 · 共 30 行

HTM
30
字号
<html>
    <head>
        <title>Accessing Style Sheets Example</title>
        <style type="text/css">
            div.special {
                background-color: red;
                height: 10px;
                width: 10px;
                margin: 10px;
            }
        </style>
        <script type="text/javascript">
            function changeBackgroundColor() {
                var oDiv = document.getElementById("div1");
                oDiv.style.backgroundColor = "blue";
                alert(oDiv.style.item(0));
            }
        </script>
    </head>
    <body>
        <div id="div1" class="special"></div>
        <div id="div2" class="special"></div>
        <div id="div3" class="special"></div>
        
        <input type="button" value="Change Background Color" onclick="changeBackgroundColor()" />

        <p><strong>Note:</strong> This example uses DOM style methods which are not supported by Internet Explorer. Therefore, an error will occur when attempting to run this example in IE.</p>
    </body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?