[英]Embed Javascript Files in body tag
I am stuck in a situation where I need to embed a javascript file to a page, but am not able to use the head tags. 我陷入了需要将javascript文件嵌入页面的情况,但我无法使用head标签。 Is there a way to embed a javascript file without having to use the head tag?
有没有办法嵌入一个javascript文件而不必使用head标签?
The code I'm using is below (src taken out): 我正在使用的代码如下(src取出):
<script type="text/javascript" src="/path/to/file.js"></script>
Any help would be greatly appreciated! 任何帮助将不胜感激!
You can put a <script>
element anywhere, including in the body. 您可以将
<script>
元素放在任何位置,包括在正文中。
Adding all <script>
s to the end of the body is a common practice (to improve load times). 将所有
<script>
添加到正文末尾是一种常见做法(以提高加载时间)。
The below is perfectly acceptable: 以下是完全可以接受的:
<html>
<!DOCTYPE html>
<head>
<!--stuff-->
</head>
<body>
<!--stuff-->
<script type="text/javascript" src="/path/to/file.js"></script>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.