<table id="table1" width="wh"border="0" cellspacing="0" cellpadding="0" height="2" >
  <tr>
    <td></td>
  </tr>
</table>如何用js给tabled的属性width赋值?

解决方案 »

  1.   

    var ta = document.getElementById("table1");
    ta.width="12%";
    这么做应该可以,学习中
      

  2.   


    <script>
            $(function(){
                $("#table1").css("width","100");
            });
        </script>
    LZ就这么个问题怎么发了三帖啊
      

  3.   

     用jquery很容易的. $("#table1").css({这里填写样式})
      

  4.   

    <script language="JavaScript" type="text/javascript">
     var t1= document.getElementById("table1");
      t1.width = "500px
      alert(t1.width);
    </script><table id="table1" width="0" border="0" cellspacing="0" cellpadding="0" height="2" >
      <tr>
        <td></td>
      </tr>
    </table><script language="JavaScript" type="text/javascript"> var t2= document.getElementById("table1");
      alert(t2.width);
    </script>
      

  5.   

    你的元素都补全了,你现在在执行第一次JS的时候table还没有被创建