我想將if語句轉換爲switch;到目前爲止,沒有運氣:將jquery「if」語句轉換爲「switch」
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");
}
}
而且到目前爲止,我已經試過如下:
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;
}
會有人好心地指出我什麼我我做錯了嗎?
我不認爲這樣的語法工作 –