我正在尝试制作横幅广告。横幅是使用宽度和高度的百分比制作的。当身体被加载时,它应该在所有分辨率下看起来都很好。但是,我的代码似乎不起作用。如果有人可以看一下,我们将不胜感激。
<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>
答案 0 :(得分:0)
您需要指定样式属性的单位。
a.style.width = … + 'px';
另外,对var
变量使用a
语句,以防止a
泄漏到全局范围(如果不是这样)。
更新:同时尝试删除document.write
来电。