Cannot read property 'getElementsByTagName' of null

在調試JS代碼的過程當中遇到錯誤:Cannot read property ‘getElementsByTagName’ of null
以下圖:
系統提示的錯誤
修改成:document.getElementsByTagName(’li’);
緣由:getElementsByTagName是document的方法,只能經過document調用web