横幅高度和宽度

时间:2012-10-21 19:20:53

标签: javascript javascript-events

我正在尝试制作横幅广告。横幅是使用宽度高度的百分比制作的。当身体被加载时,它应该在所有分辨率下看起来都很好。但是,我的代码似乎不起作用。如果有人可以看一下,我们将不胜感激。

  <script>
    function load()
    {

      document.write("Available Width: " + Math.round((screen.availWidth)/5));

      a=document.getElementById('banner');
      a.style.width=Math.round((screen.availWidth));
      a.style.height=Math.round((screen.availHeight)/5);
    }
  </script>

1 个答案:

答案 0 :(得分:0)

您需要指定样式属性的单位。

a.style.width = … + 'px';

另外,对var变量使用a语句,以防止a泄漏到全局范围(如果不是这样)。

更新:同时尝试删除document.write来电。