改一下:Javascript能把它本身用的CSS文件内的一个背景颜色数值放到它的一个变量中吗?急急急????

解决方案 »

  1.   

    应该可以吧。
    是不是先指定一个对象使用这个class然后读这个对象的style?
      

  2.   

    这是aa.html
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    <link rel="stylesheet" href="bb.css">
    <SCRIPT LANGUAGE="JavaScript">
    <!-- 
    var statusarea;
    function syzone (a){
    statusarea = a;
         a.style.backgroundColor="#99ccff";
    }
    function syztwo(a){
        statusarea = a;
    a.style.backgroundColor="#e0e0e0"
    }
    -->
    </script>
    </head>
    <body>
    <table border="1" width="100%">
      <tr>
        <td width="100%" class="color1" onmouseover="syztwo(this)" onmouseout="syzone(this)" > </td>
      </tr>
    </table>
    </body>
    </html>
    这是bb.css
    .color1 {background:#99ccff}
    .color2 {background:#e0e0e0}
    我想把html文件的所有颜色去掉,所有的颜色的都留在CSS文件中。
      

  3.   

    如果是直接解决这个例子,急功近利的方法是:
    a.style.backgroundColor="#99ccff";--> a.className = color1;
    a.style.backgroundColor="#e0e0e0";--> a.className = color2
      

  4.   

    onmouseover="this.className='color2'" onmouseout="this.className='color1'"