str.style.setAttribute("backgroundColor","#000000");

解决方案 »

  1.   


    str.style.setAttribute("background-color","#000000");--->>>>str.style.setAttribute("backgroundColor","#000000");
      

  2.   

    谢谢,我还想问个问题,
    就是怎么把用createElement创建的div删掉呢(通过写脚本)?
      

  3.   

    <html>
    <head>
    <SCRIPT LANGUAGE=javascript>  
      function bbb()
      {    
        var str = document.createElement("div");
        str.id = "asdf";
        with(str.style)
        {
          position = "absolute";
          left = "100px";
          top = "100px";
          width = "100px";
          height = "100px";
          border = "1 solid #000000";
          backgroundColor = "#000000";
          zIndex = "1";
        }
        document.body.appendChild(str);
      }  
    </SCRIPT>
    </head>
    <body>
    <input type=button value=test onclick="bbb()">
    <input type=button value=del onclick="document.all.asdf.removeNode(true)">
    </body>
    </html>
      

  4.   

    var d=document.getElementById("asdf");
    document.body.removeChild(d);