2010-08-26 7 views
1

J'ai le code suivant dans ma page:Erreur jQuery: objet non valide initialiseur

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

puis ci-dessous dans le site:

<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> 

Mais ma console d'erreur Firefox dit "objet non valide initialiseur" et pointe vers cette ligne si vous cliquez sur l'entrée. Où est l'erreur? Il me semble juste

Répondre

6

C'est ce bit à la fin:

'overflow:auto' 

Cela devrait être:

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

Dans l'ensemble, il devrait ressembler à ceci:

$(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); 
}); 

Même si c'est une valeur constante, le format doit toujours être { name: 'value' }, une seule chaîne n'est pas une syntaxe valide :)

+0

Merci. Cela fonctionne maintenant – Tim

+0

@Tim - bienvenue :) –

Questions connexes