Javascript 外部 .js 文件是否需要 <script> 标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3859966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does an external .js file require <script> tags?
提问by TroubledGuym
Does an external .js file require internal and containing tags to work?
外部 .js 文件是否需要内部和包含标签才能工作?
回答by Nick Craver
No they're not needed, in fact you'll get a syntax error if you include them.
不,它们不是必需的,实际上,如果包含它们,则会出现语法错误。
Your .js
files should contain onlyJavaScript, no HTML tags around it, like would have inside a page.
你的.js
文件应该只包含JavaScript,周围没有 HTML 标签,就像页面内部一样。
回答by Rocket Hazmat
No, it does not. The external file just needs the code.
Then you just need to do <script src="file.js" type="text/javascript"></script>
.
不,不是的。外部文件只需要代码。
然后你只需要做<script src="file.js" type="text/javascript"></script>
。
回答by sa_nyc
External Javascript should not contain tag.
外部 Javascript 不应包含标签。