最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery Error: Invalid object initializer - Stack Overflow

programmeradmin6浏览0评论

I have the following code in my page:

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

and then below in the 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>

But my Firefox error console says "invalid object initializer" and points to this line if click the entry. Where is the error? It seems right to me

I have the following code in my page:

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

and then below in the 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>

But my Firefox error console says "invalid object initializer" and points to this line if click the entry. Where is the error? It seems right to me

Share Improve this question asked Aug 26, 2010 at 10:01 TimTim 7335 gold badges12 silver badges19 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

It's this bit on the end:

'overflow:auto'

That should be:

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

Overall it should look like this:

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

Even if it's a constant value, the format still has to be { name: 'value' }, a single string just isn't valid syntax :)

发布评论

评论列表(0)

  1. 暂无评论