我正在尝试将if语句转换为switch;到目前为止没有运气:
<button id="myBtn" onclick="app.click()">Click me</button>
&#13;
到目前为止,我尝试了以下内容:
if (myapp_config.thisDevice == 'desktop') {
var primaryNavHeight = $('#primary-nav').height() + app_get_header_height,
pageWrapperHeight = $('#page-wrapper').height();
if (primaryNavHeight > pageWrapperHeight) {
$('#page-wrapper').css("min-height", primaryNavHeight + "px");
}
if (primaryNavHeight < pageWrapperHeight) {
$('#page-wrapper').css("min-height", $(window).height() + "px");
}
}
&#13;
有人会善意地指出我做错了什么吗?
答案 0 :(得分:1)
您没有计算primaryNavHeight和pageWrapperHeight。这可能是问题所在。
var primaryNavHeight = $('#primary-nav').height() + app_get_header_height,
pageWrapperHeight = $('#page-wrapper').height();
switch (myapp_config.thisDevice == 'desktop') {
case (primaryNavHeight > pageWrapperHeight):
// do stuff
$('#page-wrapper').css("min-height", primaryNavHeight + "px");
break;
case (primaryNavHeight < pageWrapperHeight):
// do stuff
$('#page-wrapper').css("min-height", primaryNavHeight + "px");
break;
}