2013-01-16 42 views
-1

我有一个jquery,如果不挺的工作应该的方式发言,我觉得已经很接近了,但似乎并不十分想要的工作:jQuery的if语句格式

我就喜欢如下: 如果它是一个ios设备我希望它做一件事,如果它是一个高度大于500像素但小于830的窗口,那么做另一件事,如果它不是那些事情做第三件事

var deviceAgent = navigator.userAgent.toLowerCase(); 
var agentID = deviceAgent.match(/(iphone|ipod|ipad)/); 


if(agentID) { 
    $("#about_container").css({ 
     height: $(window).height() + 500 
    }); 
    $("#about_main_header_container").css({ 
     paddingBottom: (($(window).height() - $("#about_content_total").outerHeight(true)) /2) - 50 
    }); 
    $("#services_wrapper").css({ 
     height: $(window).height() + 190 
    }); 
    $("#services_main_header_container").css({ 
     paddingBottom: (($(window).height() - $("#services_container").outerHeight(true)) /2) - 10 
    }); 
} 
else if ($(window).height() > 500, $(window).height() < 830) { 
$("#about_container").css({ 
    height: 830 
});  
$("#services_wrapper").css({ 
    height: 830 
}); 
$("#services_main_header_container").css({ 
    paddingBottom: 160 
}); 
$("#about_main_header_container").css({ 
    paddingBottom: 130 
}); 
} 
else { 
    $("#about_container").css({ 
     height: $(window).height() - 65 
    }); 
    $("#about_main_header_container").css({ 
     paddingBottom: (($(window).height() - $("#about_content_total").outerHeight(true)) /2) - 175 
    }); 
    $("#services_wrapper").css({ 
     height: $(window).height() - 100 
    }); 
    $("#services_main_header_container").css({ 
     paddingBottom: (($(window).height() - $("#services_container").outerHeight(true)) /2) - 175 
    }); 
} 
+0

...你想如何工作? – Codeman

+0

你的问题是什么?你能否给我们更多关于“不太有效”的细节? –

+0

如果它是一个ios设备我希望它做一件事,如果它是一个高度大于500像素但小于830的窗口,那么做另一件事,如果它们都不是这些东西做第三件事 – loriensleafs

回答

1
else if ($(window).height() > 500, $(window).height() < 830) 

是不对的,应该是:

else if ($(window).height() > 500 && $(window).height() < 830) 

在javascript中,a,b只会返回b

+0

嗯,但他们'不是一回事吗? – loriensleafs