#tech {
    position: absolute;
    border: 2px solid blue;
    width: 30px;
    height: 30px;
    top: 50px;
}
<div id='tech'></div>
我是用的getComputedStyle(document.getElementById('tech'), null).top来取的top的值,但是这个好像是只读的,如果我要修改的话,应该怎么改?用document.getElementById('tech').top好像不行。CSSJavaScript

解决方案 »

  1.   


     <style>
     .a{
         position: absolute;
         border: 2px solid blue;
         width: 30px;
         height: 30px;
         top: 50px;
     }
     </style>
    <div id='tech' class="a"></div>
    <script type="text/javascript">
    var d=document.getElementById('tech');
    d.style.top='500px';
    </script>
      

  2.   

    楼上正解,样式要通过style属性来访问div.style.xx = '';
      

  3.   

    还有一个办法是:
    document.getEelementById("").class="class1";
    or
    document.getEelementById("").class="class2";
      

  4.   

    document.getEelementById("").className="class1";
    or
    document.getEelementById("").className="class2";
    上面给错了