對下述結構代碼,文檔中只有<script>和<html>,會提示appendChild未定義,但是加上window.onload = function().....就可以正常執行,如何解釋?謝謝<script>var tester = document.createElement('div');
tester.style.display = 'inline-block';
tester.style.fontSize = '30px';
tester.innerHTML = 'Segment';document.body.appendChild(tester);console.log(tester.offsetWidth) // 120</script>
如何解釋這段代碼?
慕姐4208626
2018-08-14 09:09:55