1

为什么 ReferenceError: $ is not defined

<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");

//Uncaught ReferenceError: interface is not defined Help

4

1 回答 1

2

尝试 :

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

或者

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

查看更多:: LABjs 文档

于 2013-02-10T05:35:40.100 回答