2017-10-22 76 views
0

我想在加载所有组件时从主体中移除类“active”。为此,我编写了以下jquery代码片段,它在Chrome中运行得很好,但在Firefox中,加载所有组件后,“active”类不会被removeClass函数删除。如何在文档开始加载时加载类并在文档加载完成时删除类

$(document).ready(function($){ 


     $("body").addClass("active"); 


}); 


$(window).on('load', function() { 

     $("body").removeClass("active"); 

}); 
+2

你是否检查哪一个先运行? –

+0

@FastSnail加载函数首先在Firefox中运行,并且ready函数首先在Chrome中运行。 现在我得到了原因,但我该如何实现呢? –

+0

你能解释一下你在做什么? –

回答

0

还有什么可能导致问题..?

我在Chrome和Firefox中试过这个,它工作正常....文件首先加载...也许尝试运行下面的代码,看看这是否在你的Firefox上做同样的事情...?

但它可能是FF版本,也可能是jQuery版本。

我有FF 56.0(32位),它的更新,因为我们说话:-P 和jQuery 2.2.4

<!doctype html> 
    <html> 
    <head> 
     <title>Quick Loading test</title> 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> 
    </head> 
    <body> 
     <h1>testing</h1> 

     <img src="http://www.guoguiyan.com/data/out/113/69175307-large-wallpapers.jpeg"> 

     <script> 


     $(window).on('load', function() { 
      $('body').removeClass('active'); 
      console.log('window load'); 
     }); 


     $(document).ready(function($) { 
      $('body').addClass('active'); 
      console.log('doc ready'); 
     }); 

     </script> 
    </body> 
    </html> 

我发现关于该此链接...

https://github.com/jquery/jquery/issues/3194

所以也许试试

$(window).on('load', function() { 
     $('body').removeClass('active'); 
     console.log('window load'); 
    }); 


    $(function() { 
     $('body').addClass('active'); 
     console.log('doc ready'); 
    }); 
+0

在我的FF窗口中首先加载。 –

+0

我在原始文章中添加了一些发现。尝试没有$(document).ready() – Pocketninja

+0

同样的事情发生了 https://prnt.sc/h0f2a7 –