Javascript:错误'对象必需'。我无法破译它。你能?

我在我的一个网站上使用了一个名为“Facelift 1.2”的javascript,虽然该脚本适用于Safari 3,4b和Opera,OmniWeb和Firefox,但它并不适用于任何IE版本。 但即使在工作浏览器中我得到以下错误我无法破译。 也许在适当的时候 - 有更多的经验Javascript - 我将能够,但现在我想我会问你们中的一些人,在这里。 以下是我在IETester中测试Interet Explorer 6,7和8的页面时出现的错误弹出窗口: IE错误弹出http://img21.imageshack.us/img21/3651/err2.png 以下内容来自Firefox 3.0.6中的Firebug控制台: Firebug控制台日志http://img100.imageshack.us/img100/3636/err3.png 该网站是:http://www.457cc.co.nz/index.php如果它可以帮助您看到行动中提到的问题。 我也查了一下620对应的是: “第76行”是:
this.isCraptastic = (typeof document.body.style.maxHeight=='undefined');
这是这段代码的一部分(取自flir.js):
// either (options Object, fstyle FLIRStyle Object) or (fstyle FLIRStyle Object)
,init: function(options, fstyle) { // or options for flir style
    if(this.isFStyle(options)) { // (fstyle FLIRStyle Object)
        this.defaultStyle = options;
    }else { // [options Object, fstyle FLIRStyle Object]
        if(typeof options != 'undefined')
            this.loadOptions(options);

        if(typeof fstyle == 'undefined') {
            this.defaultStyle = new FLIRStyle();
        }else {
            if(this.isFStyle(fstyle))
                this.defaultStyle = fstyle;
            else
                this.defaultStyle = new FLIRStyle(fstyle);
        }
    }

    this.calcDPI();

    if(this.options.findEmbededFonts)
        this.discoverEmbededFonts();

    this.isIE = (navigator.userAgent.toLowerCase().indexOf('msie')>-1 && navigator.userAgent.toLowerCase().indexOf('opera')<0);
    this.isCraptastic = (typeof document.body.style.maxHeight=='undefined');

    if(this.isIE) {
        this.flirIERepObj = [];
        this.flirIEHovEls = [];
        this.flirIEHovStyles = [];    
    }
}
整个脚本也可以在我的服务器上找到:http://www.457cc.co.nz/facelift-1.2/flir.js 我只是不知道从哪里开始寻找错误,特别是因为它只影响IE,但在其余部分工作。也许你们有个主意。我很乐意听到他们。 谢谢阅读。 Jannis PS:这是Opera的错误控制台报告:
JavaScript - http://www.457cc.co.nz/index.php
Inline script thread
Error:
name: TypeError
message: Statement on line 620: Cannot convert undefined or null to Object
Backtrace:
  Line 620 of linked script http://www.457cc.co.nz/facelift-1.2/flir.js
                    document.body.appendChild(test);
  Line 70 of linked script http://www.457cc.co.nz/facelift-1.2/flir.js
            this.calcDPI();
  Line 2 of inline#1 script in http://www.457cc.co.nz/index.php
            FLIR.init();
stacktrace: n/a; see 'opera:config#UserPrefs|Exceptions Have Stacktrace'
    
已邀请:
我同意tvanfosson - 你之所以得到这个错误很可能是因为你在页面加载之前调用了
init()
,所以
document.body
还没有定义。 在您链接的页面中,您应该将以下代码移动到页面底部(就在关闭html标记之前:
<script type="text/javascript">
    FLIR.init({ path: 'http://www.457cc.co.nz/facelift-1.2/' });
    FLIR.auto();
</script>
更好的是,您应该将初始化附加到文档的
ready
事件。如果你这样做,你甚至不需要将你的javascript移动到文件的底部。使用jquery:
$(document).ready( function(){
    FLIR.init({ path: 'http://www.457cc.co.nz/facelift-1.2/' });
    FLIR.auto();
});
更多关于jquery的document.ready event&raquo;     
编辑上下文的答案。有关正确的分辨率,请参阅@ Triptych(已接受)答案。 我的建议是将javascript包含在标记的末尾。我认为发生的事情是代码在DOM完全加载之前执行,因此当您在确定maxHeight样式属性时尝试引用它时,document.body为null。将javascript的包含移动到标记的末尾应足以保证文档的主体至少被加载并避免此特定错误。
 ... rest of html....

    <script type='text/javascript'
            src='http://www.457cc.co.nz/facelift/flir.js'>
    </script>
 </body>
 </html>
    
安装.net Framework v2并解决问题。     

要回复问题请先登录注册