Javascript $(window).load(函数()在语句中)?
不确定是否可以在语句中包含$(window.load)(function()),是否正确Javascript $(window).load(函数()在语句中)?,javascript,jquery,Javascript,Jquery,不确定是否可以在语句中包含$(window.load)(function()),是否正确 else if (isAndroid){ $('.apple, .bottomcta, .bottomapple, .cta, .cta2').hide(); $('.android').show(); $(window).load(function() { if ($('.yes2, .YES2').css('display') == 'n
else if (isAndroid){
$('.apple, .bottomcta, .bottomapple, .cta, .cta2').hide();
$('.android').show();
$(window).load(function() {
if ($('.yes2, .YES2').css('display') == 'none') {
$('#bottombadge > p, #badge > p, .bottomandroid, .android, .bottomapple, .apple').remove();
$('#button, .cta, .bottomcta').show();
}
else if ($('.no, .NO').css('display') == 'block') {
$('.bottomapple, .apple').remove();
}
}
);
}
有什么想法吗?是的,你可以
毕竟,您只是使用jQuery将事件处理程序附加到窗口
对象的加载
事件
但是,正如@Siphalor所评论的那样,它并没有那么有用:
代码永远不会执行,因为页面应该具有allready
装载
相反,您应该执行以下操作:
$(window).load(function() {
if (isAndroid){
$('.apple, .bottomcta, .bottomapple, .cta, .cta2').hide();
$('.android').show();
// more code
我想不会有任何错误,但是代码永远不会执行,因为页面应该已经加载完毕call?调用是执行
else中的任务所必需的。.if
?正在使用哪个版本的jQuery?谢谢。我使用的是2.1.1,我有各种语句。其中包含另一个语句的语句不能正常工作。if(isiPhone>-1){$('.apple,.bottomapple,#bottombagde').show()$('.android,.cta,.bottomcta,.bottomandroid').remove();if($('.yes,.yes').css('display')='none'){$('.cta,.cta2,.bottomcta').show();}}有什么想法吗?谢谢。我的代码在没有$(window.load(function))的情况下运行得很好直到另一个里面有一个语句:else if(isiPhone>-1){$('.apple,.bottomapple,#bottombagde').show();$('.android,.cta,.bottomcta,.bottomandroid').remove();if($('.yes,.css('display')='none'){$('.cta,.cta2,.bottomcta').show()); } }