在頁面上加上<script></script>只有2個地方:head中,body體中
如果外部的JS文件,在head中加,寫頁面特效js放在body后面。
<html> <head> <title>JS代碼的位置</title> <style> div{ width:80px; height:90px; background-color: #f00; } </style> <script src="index.js"></script> <!--我在head里面--> </head> <body> <div class="weizhi"> </div> </body> <script> <!--實際上我在body里面--> show(); </script> </html>
在瀏覽器中的實際效果: