我试图制作一个图像作为我的背景,并符合浏览器的尺寸。然而,我明白了:expmrt.html:15 Uncaught TypeError: Cannot set property 'width' of null。
//Get the browser legth and height, then after the code is done, time out in 300 miliseconds.
function ScreenLoop() {
var Width = window.innerWidth;
var Height = window.innerHeight;
alert("Width: " + Width + " and also Height: " + Height) //Debugging reasons
document.getElementById("theimage").width = Width; // Where the error: expmrt.html:15 Uncaught TypeError: Cannot set property 'width' of null) occures for some reason.
document.getElementById("theimage").height = Height;
setTimeout(ScreenLoop(), 300);
};
ScreenLoop();<img src="tl2fZkc.png" id="theimage" width="50" height="50" alt="theimage" />
发布于 2016-03-03 11:12:05
从窗口调用load事件中的ScreenLoop()
window.onload = function() {
ScreenLoop();
}https://stackoverflow.com/questions/35770479
复制相似问题