jsp js 加载顺序
<script>
alert(111);
test();
$(document).ready(function(){
test();
});
</script>
<body>
</body>
<script>
alert(222);
$(document).ready(function(){
alert(444);
});
function test(){
alert(333);
}
</script>
整体是从上到下执行,先执行 alert(111),然后,test()现在test方法还没有被加载,会报错。
继续加载,加载body里面的东西,然后 alert(222),然后加载test()。
加载完成后,执行$(document).ready(function() 中的 test(),然后执行 alert(333)。
<script>
alert(111);
test();
$(document).ready(function(){
test();
});
</script>
<body>
</body>
<script>
alert(222);
$(document).ready(function(){
alert(444);
});
function test(){
alert(333);
}
</script>
整体是从上到下执行,先执行 alert(111),然后,test()现在test方法还没有被加载,会报错。
继续加载,加载body里面的东西,然后 alert(222),然后加载test()。
加载完成后,执行$(document).ready(function() 中的 test(),然后执行 alert(333)。