2013-02-08 49 views
1

为什么ReferenceError:$未定义使用Lab.js加载模块

<script src="LAB.js"></script> 
      <script> 
    $LAB.script("jquery/jquery.js") 
    </script> 

    </body> 

    <p><?php echo mt_rand(89,161464) ?></p> 

    <script> 
//Uncaught ReferenceError: $ is not defined 

$(document).ready(function(){ 
    console.log('reddy'); 
    $("p").css('color','red'); 
    }) 
</script> 

但工作:

window.onload=function(){ 
     $("p").css('color','red'); 
     } 

2. item1.js

var interface={name:'interface'}; 

item2.js

interface.hu={name:'int'}; 

$LAB.script("item2.js").wait(); 
$LAB.script("item1.js"); 

//未捕获的ReferenceError:接口没有定义 帮助

回答

2

尝试:

$LAB.script("jquery/jquery.js").wait(function() { 
    if(window.jQuery) { //is jquery loaded 
     $("p").css('color','red'); 
    } 
}); 

OR

$LAB.script("jquery/jquery.js").wait(function() { 
    $(document).ready(function() { 
     $("p").css('color','red'); 
    } 
}); 

查看更多:: LABjs Doc