<table></table>问题:计算出当前表格的高度,和当前页面的高度,然后对比当表格高度 > 页面高度时 表格的宽度等于99%  <table width="99%"></table>当表格高度 < 页面高度时 表格的宽度等于100% <table width="100%"></table>请问这个应该怎么写,谢谢。

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>hello</title></head><body>
    <table id="table" width="1000" border="1" height="900">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table></body>
    </html>
    <script>
    var body_height =document.body.clientHeight;
    var table_height = document.getElementById("table").clientHeight;
    alert("body_height"+body_height+"ssssss" + table_height)
    if(body_height>table_height){
    document.getElementById("table").style.width = "100%";
    }else{
    document.getElementById("table").style.width = "99%";
    }
    </script>