我想根据窗口的高度和宽度创建内容图像的背景,原因是它不起作用。你能在哪里弄错我的帮助吗? JSFIDDLE
<div class='content'>
<p>Hi there</p>
</div>
var height = $(window).height();
var width = $(window).width();
$(window).on('click', function(){
alert(height);
})
var content = $('.content');
content.css({
'width' : width + 'px'
'height' : height + 'px'
});
答案 0 :(得分:0)
你错过了一个逗号,
content.css({
'width' : width + 'px',
//------------------------^
'height' : height + 'px'
});
答案 1 :(得分:0)
var height = $(window).height();
var width = $(window).width();
$(window).on('click', function(){
alert(height);
})
var content = $('.content');
content.css({
'width' : width + 'px',
'height' : height + 'px'
});
如果某些内容在JavaScript中不起作用,首先要按F12并检查控制台输出。