IE 7和8无法识别jQuery的高度和宽度?

时间:2013-09-17 09:00:04

标签: javascript jquery internet-explorer

我使用config变量写了几个函数。这是它的样子:

scripts = function() {
    var config = {
        windowWidth: $(window).width(),
        windowHeight: $(window).height()
    }

    function generatePages() {
        $('section.main').each(function() {
            $(this).css({
                'width' : config.windowWidth,
                'height': config.windowHeight
            });

            if($(this).children('.more').length) {
                $(this).children('.more').css('line-height',config.windowHeight+'px')
            }
        });
    }

    return {
        config:config,
        generatePages:generatePages
    }
}();

scripts.generatePages();

它适用于所有浏览器,但IE 7-9无法运行generatePages,它似乎无法“理解”$(window).width()height()。我该怎么办?

2 个答案:

答案 0 :(得分:5)

当您评论我的问题时,您使用的是jQuery 2.0.3,您无法在旧浏览器中使用jQuery 2+:

正如所承诺的,这个版本留下了旧的Internet Explorer 6,7和8浏览器。作为回报,它更小,更快,并且可以在JavaScript环境中使用,其中旧IE兼容性所需的代码经常导致其自身的问题。但不要担心,jQuery团队仍然支持在IE 6/7/8上运行的1.x分支。您可以(并且应该)继续在需要适应旧浏览器的网站上使用jQuery 1.9(以及即将发布的1.10)。

来源:http://blog.jquery.com/2013/04/18/jquery-2-0-released/

答案 1 :(得分:0)

尝试添加px指标:

$(this).css({
    'width': config.windowWidth + 'px',
    'height': config.windowHeight + 'px'
});