猿问

javascript访问样式表


javascript中用style来访问样式表,有什么区别

<!DOCTYPE html>

<html>

    <head>

        <meta charset="utf-8">

        <style type="text/css">

         div.special{

         background-color: red;

         height: 80px;

         width: 80px;

         margin: 5px;

         }

        </style>

        <script type="text/javascript">

         function getBackgroundColor(){

         var oDiv1 = document.getElementById("div1");

          alert(oDiv1.style.backgroundColor);

         }       //警告框返回的是空字符串


            function changeBackgroundColor(){

                var oDiv4 = document.getElementById("div4");

                oDiv4.style.backgroundColor = "blue";

            }  //能正确改变颜色

        </script>

    </head>

    <body>

     <div id="div1"></div>

     <div id="div2"></div>

     <div id="div3"></div>

     <input type="button" value="getBackgroundColor" onclick="getBackgroundColor()"/>


        <div id="div4"></div>

        <div id="div5"></div>

        <div id="div6"></div>

        <input type="button" value="changeBackgroundColor" onclick="changeBackgroundColor()"/>

    </body>

</html>


牛肉速冻矮子
浏览 901回答 1
1回答

慕瓜9220888

FDPUTJCHKFZVWVOLEXBCDSOXDATLVEGBRUKKTUWBGQTWPCDFDPQQDDRPRTFJTDGNYQQPVBMQOJBQLTNGDXBJSKKFLYULDSSLSYECJRASIDMJPQBQZSZYPABQIUEAQGDOQZHOEQULTRTVBERBOMYHGHUFHXIQOELXJISNODMIBREXEQFHGAMWBWBDBBUHRKHQVXJJGPEFHTOLBHBUUAYRUAGNQRPRGJWMIXLMBFFIBKSJLXJZPBKSKCGOXXUXGLTBGDTMZRRKIUXDZDEMLTVYRRURCOJVUERNHRDYADWWJQIAFOQGBYYGHBWYYUUQXGLNQMCMBCUDLOYJPIGSGILVOXZRTRXGJGWXBGYQQTZPKLDOKDJTCKRAFUXNJTZDSNPMCZCCUVAWPFLVTUIHDWGSMEPLQTWFIRKVRBZMVFSKSGZJIFFITNFBEXRAALWFHFYRUMLFXJMYOYWVZHMYBRFPHGMUTQMPSABGYKDMJMABDVADAQWITVDLVYOUVTBQYBYCVEIQIHKDJZVMVXPFCPIFWOTVEOHUPDSXTZWPISGLNZMYVVWDWRZPPPCCKZRZ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式写div标签内  就可以获取了<div id="div1" style="background:blue"></div>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答