const heightOutput = document.querySelector('#height');
const widthOutput = document.querySelector('#width');
function reportWindowSize() {
heightOutput.textContent = window.innerHeight;
widthOutput.textContent = window.innerWidth;
}
window.onresize = reportWindowSize;
Run Code Online (Sandbox Code Playgroud)
为什么不
window.onresize = reportWindowSize()
呢?这是函数调用,我想触发它。但是当我添加 () 时它不起作用。