您可以将包含JavaScript的<script>标记放置在网页中的任何位置,但是通常建议您将其保留在<head>标记或<body>标记内。
在<body>元素中添加JavaScript对性能有好处。这是在<body> ... </ body>下添加<script>的示例-
<html>
<body>
<script>
<!--
document.write("你好,世界!")
//-->
</script>
</body>
</html>
这是在<head> ... </ head>下添加<script>的示例-
<html>
<head>
<script>
<!--
document.write("你好,世界!")
//-->
</script>
</head>
<body>
</body>
</html>