1 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 2 <script type="text/javascript"> 3 (function(){ 4 var a = 2, 5 srcPath; 6 if(a == 1){ 7 srcPath = 'http://jquery.com/files/social/js/jquery.tabs.js'; 8 }else{ 9 srcPath = 'http://static.jquery.com/files/rocker/scripts/custom.js'; 10 } 11 document.write('<script type="text/javascript" src="' + srcPath + '"><\/script>'); 12 })(); 13 </script> 14 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
如上面的代码,在IE6下,加载的顺序如下图所示:
而在IE7,8,9, chrome,firefox下,加载顺序如下:
可见是有区别的,解释也不用多说,后者先加载外联JS(类似预加载),再按序,从上到下执行内联JS