简体   繁体   English

未定义的类型错误“defaultView”与基本的jQuery

[英]Undefined Type Error “defaultView” with basic jQuery

I'm trying to build a basic resizing script using just raw jQuery v1.5.1 (Script below). 我正在尝试使用原始jQuery v1.5.1(下面的脚本)构建一个基本的大小调整脚本。 For some reason it throws the following error and won't continue with running the script. 由于某种原因,它会抛出以下错误,并且不会继续运行脚本。

This is being tested with Chrome, Mac OSX 这是使用Chrome,Mac OSX进行测试的

Error Uncaught TypeError: Cannot read property 'defaultView' of undefined 错误Uncaught TypeError: Cannot read property 'defaultView' of undefined

Code: 码:

$(document).ready( function() {
    /* Set initial #site width */   
    stretch_portal_content();
    $(window).resize( stretch_portal_content );
});


function stretch_portal_content() {
    alert($('#site').width());
    $('#left-container').width(
        $('#site').width()-150
    );

    if ($(window).height() > $('body').innerHeight()){
        $('#site').height(
            $(window).innerHeight()
        );
    }

}

Example HTML 示例HTML

<!DOCTYPE html5>
<html>
    <head>
        <title></title>
        <link media="screen" rel="stylesheet" href="style.css" />
    </head>
    <body>
        <div id="site">
        <div id="left-container">
            <div class="inner">
                <ul id="grid">
                    <li>Story 1</li>
                    <li>Story 2</li>
                    <li>Story 3</li>
                    <li>Story 4</li>
                    <li>Story 5</li>
                </ul>
            </div>
        </div>
        <div id="right-container">
            <ul id="category-list">
                <li><a href="#">Category 1</a></li>
                <li><a href="#">Category 2</a></li>
                <li><a href="#">Category 3</a></li>
                <li><a href="#">Category 4</a></li>
                <li><a href="#">Category 5</a></li>
                <li><a href="#">Category 6</a></li>
                <li><a href="#">Category 7</a></li>
            </ul>
        </div>
        <div class="clear"></div>
    </div>
    <script type="text/javascript" src="javascript/jquery.js"></script>
    <script type="text/javascript" src="javascript/core.js"></script>
</body>
</html>

Inner Height Documentation 内高度文档

The issue is the innerHeight function is not applicable to the window object. 问题是innerHeight函数不适用于window对象。 Use height instead. 请改用高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM