$(window).load() 在 Modernizr 调用后...不工作

$(window).load() after Modernizr call... Not Working

我有这个HTML

<head>
<script src="modernizr.js"></script>
<script>
    Modernizr.load([{
        // jQuery
        test: document.getElementsByClassName, // IE>8
        nope: 'js/jquery-1.11.3.min.js',
        yep: 'js/jquery-2.1.4.min.js'
        },{
        test: Modernizr.somefunction,
        load: 'somecode.js'
    }
</script>
</head>

和somecode.js

$(window).load(function(){
   //somecode
});

不工作(有时工作,有时不只在 Google Chrome)。

我也不能使用 $(document).ready(),但可以用 setTimeout 立即修复它(神奇!)

$(document)ready(function(){
   setTimeout(function(){
      // some code
   });
});

有什么办法可以修复 jQuery 加载方法吗?

尝试使用complete回调

Modernizr.load([{
        // jQuery
        test: document.getElementsByClassName, // IE>8
        nope: 'js/jquery-1.11.3.min.js',
        yep: 'js/jquery-2.1.4.min.js',
        complete: function () {
            Modernizr.load('somecode.js');
        }
    }
]);

有时,Modernizr 会在加载一些小对象后运行。

修复:

$(document)ready(function(){
   setTimeout(function(){

      function NewFunction(){
         // some code
         }
      // For Tags action
      if($('selector').find('otherselector').length > 0 ){
          NewFunction();
          }else{
             $('selector').load(function(){
                NewFunction(); 
                 });
              }
        // For Attributes action      
      if((typeof($('selector').attr('attributename')) === 'undefined') || ($('selector').attr('attributename') === null)){
          NewFunction();
          }else{
             $('selector').load(function(){
                NewFunction(); 
                 }); 
              }
        // Width | Height img
        if($('imgselector').height() !== '0px'){
            NewFunction();
          }else{
             $('imgselector').load(function(){
                NewFunction(); 
                 });
              }

   });
});