JS代码放在哪里比较好!

在页面上加上<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>

在浏览器中的实际效果:



原文地址:https://www.cnblogs.com/wangjian666/p/6637196.html