Tim*_*Tim 1 html javascript jquery dom
我的页面中有以下代码:
<div id="data_body_container" style="overflow: auto; width: 880px; height: 500px;">
...
</div>
Run Code Online (Sandbox Code Playgroud)
然后在网站下面:
<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>
Run Code Online (Sandbox Code Playgroud)
但我的Firefox错误控制台说"无效对象初始化程序"并指向此行,如果单击该条目.错误在哪里?对我来说似乎是对的
最后是这一点:
'overflow:auto'
Run Code Online (Sandbox Code Playgroud)
那应该是:
overflow: 'auto'
//or, to match your styling...
'overflow': 'auto'
Run Code Online (Sandbox Code Playgroud)
总的来说,它应该是这样的:
$(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);
});
Run Code Online (Sandbox Code Playgroud)
即使它是一个常量值,格式仍然必须是{ name: 'value' },单个字符串只是无效的语法:)