jac*_*on5 -3 javascript jquery
无论出于何种原因,从控制台运行时都可以使用:
var wh=window.innerHeight;
var h= wh-345;
$('.hidehome').attr('style', 'display:block;height:'+h+'px;width:100%');
Run Code Online (Sandbox Code Playgroud)
但这不是:
$(document).ready(function() {
var wh=window.innerHeight;
var h= wh-345;
$('.hidehome').attr('style', 'display:block;height:'+h+'px;width:100%'); )};
Run Code Online (Sandbox Code Playgroud)
我不知道为什么.控制台告诉我
Syntax error at line 4: expected expression, got ')'
h+'px;width:100%'); )};
--------------------^
Run Code Online (Sandbox Code Playgroud)
这显然意味着我的代码出了问题,但我仍然无法理解.
您的括号和大括号需要切换:
$('.hidehome').attr('style', 'display:block;height:'+h+'px;width:100%'); )};
^^
Right here
Run Code Online (Sandbox Code Playgroud)
另外,请考虑使用以下css方法:
$('.hidehome').css({
'display': 'block',
'height': h + 'px',
'width': '100%'
});
Run Code Online (Sandbox Code Playgroud)