getElementById Object doesn't support this property or method

代码:

master_headertop =document.getElementById('master_headertop');
if (master_headertop)
      master_headertop.style.display = 'none';

错误提示:

Object doesn't support this property or method.

更正为:

var master_headertop =document.getElementById('master_headertop');
if (master_headertop)
        master_headertop.style.display = 'none';

以下也是错误的:

getElementById('master_headertop').style.display = 'none';

原文地址:https://www.cnblogs.com/emanlee/p/1784488.html