我觉得一个一个属性设置,效率太低了如果能整个写好,然后赋值,该多好...

解决方案 »

  1.   

    document.getElementById("div2").style.cssText ="很多定义一次写"
      

  2.   

    firefox可以使用document.getElementById("name").setAttribute("style","width:10px;height:10px;border:solid 1px red;");
    IE 中则必须使用
    document.getElementById("name").style.cssText="width:10px;height:10px;border:solid 1px red;";
      

  3.   

    在jquery中用的class比较多,在这方面js做的不够好,class就是类的意思,这样可以控制布局一样的class了,在jquery中是这样写的,$(".test").click(function(){alert("hi")});
    <div class="test">点击</div>
    <div class="test">再点击</div>
    <div class="test">后点击</div>
    <div class="test">最后点击</div>
      

  4.   

    我照着2楼的写了一个脚本,但运行后浏览器总是提示后为空或不是对象,请帮助看一下是什么原因?谢谢。
    <p name="title_three" onclick="color_red()">这是第3个P元素</p>
        function color_red()
         {
          document.getElementsByTagName("title_three").style.cssText = "color:red;";
          return true;
         }
      

  5.   

    关键是这里:
    document.getElementsByName("title_three")[0].style.cssText = "color:red;";
      

  6.   

    document.getElementById("div2").style.cssText="position:absolute; left:0px;  top:0px;  width:100%;   height:100%; background-color:red;"
    但需要注意:  单独设置也是有其存在的价值的!!!例如,当你仅仅只想修改背景色,而不想修改大小和定位时,单独设置就显得极为需要了.如果你选择整体设置,你就的为所有的属性重新写一遍!!!