var adiv = document.createElement("div");
var bdiv = document.createElement("div");
adiv.setAttribute("style","padding-left:10px;");
bdiv.setAttribute("style","display:none;padding-left:10px;");就是这样的两个几句代码,针对FF得到了想要的结果。
针对IE,set的属性没有起到作用。高手帮我看看,应该怎么改进?

解决方案 »

  1.   


    <script type="text/javascript"> 
    window.onload=function(){
    var adiv = document.createElement("div");
    var bdiv = document.createElement("div");
    adiv.innerHTML = "xxxx"
    bdiv.innerHTML = "bbbbb"
    adiv.style.cssText = "padding-left:10px;";
    bdiv.style.cssText = "display:none;padding-left:10px;";
        document.body.appendChild(adiv);
        document.body.appendChild(bdiv);}
    </script> 
      

  2.   

    似乎不得行 我还是把代码贴全点:var div = document.getElementById("b"+bid);

    var bdiv = document.createElement("div");
    bdiv.setAttribute("id","b"+o.id);
    bdiv.setAttribute("style","display:none;padding-left:10px;");
     
    var a2 = document.createElement("a");
    a2.setAttribute("onclick","bb('"+o.id+"')");
    a2.setAttribute("href","#");var t2 = document.createTextNode("-  "+o.name);a2.appendChild(t2);
    bdiv.appendChild(a2);div.appendChild(adiv);
    div.appendChild(bdiv);

    if(document.all)div.outerHTML = div.outerHTML;
      

  3.   

    FF下不支持div.setAttribute(type,value);
    用div.type=value;