2010-08-26 51 views
1

我已經在我的網頁下面的代碼:jQuery的錯誤:無效的對象初始化

<div id="data_body_container" style="overflow: auto; width: 880px; height: 500px;"> 
... 
</div> 

,然後在下面的網站:

<script type="text/javascript"> 
     $(window).resize(function() { 
        var windowWidth = $(window).width() - 50; 
        var windowHeight = $(window).height() - 50; 

      $('#data_body_container').css({'width': windowWidth+'px', 'height': windowHeight+'px','overflow:auto'}); 

     alert('Resize to '+ windowWidth + 'x'+windowHeight); 
     }) 

    </script> 

但我的Firefox錯誤控制檯說:「無效的對象初始化」並點擊這條線,如果點擊條目。錯誤在哪裏?看來我的權利

回答

6

這是對結束該位:

'overflow:auto' 

這應該是:

overflow: 'auto' 
//or, to match your styling... 
'overflow': 'auto' 

整體而言,這應該是這樣的:

$(window).resize(function() { 
    var windowWidth = $(window).width() - 50, 
     windowHeight = $(window).height() - 50; 

    $('#data_body_container').css({'width': windowWidth+'px', 'height': windowHeight+'px', 'overflow': 'auto'}); 
    alert('Resize to ' + windowWidth + 'x' + windowHeight); 
}); 

即使這是一個常數值,格式仍然是{ name: 'value' },單個字符串只是無效的語法:)

+0

謝謝。它現在有效 – Tim 2010-08-26 10:08:05

+0

@Tim - 歡迎:) – 2010-08-26 10:08:45