<html>
<body>
<a id='aid1'> aaa </a>
</body>
</html>
想通过JS设置A标签的背景色,我是这样做的,但是行不通:
<html>
<body>
<a id='aid1'> aaa </a>
<SCRIPT language="JavaScript">
document.getElementById('aid1').style='background-color:#c0d2ec';
</SCRIPT>
</body>
</html>

解决方案 »

  1.   

    document.getElementById('aid1').style["background-color"]='#c0d2ec';
      

  2.   

    document.getElementById('aid1').style["backgroundColor"]='#c0d2ec';
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>test</title>
    <style>
    #test{
    width:200px;
    height:200px;
    }
    </style>
    <script>
    function test(){
    document.getElementById("test").style.backgroundColor = "red";
    }
    </script>
    </head>
    <body>
    <div id="test" onclick="test()">点击</div>
    </body>
    </html>
      

  4.   

    document.getElementById('aid1').style.backgroundColor='#c0d2ec'