我应该放在哪里<script> tags in HTML markup?

馋奶兔 提交于 2020-08-12 15:13:29

问题:

When embedding JavaScript in an HTML document, where is the proper place to put the <script> tags and included JavaScript? 在将JavaScript嵌入HTML文档中时,将<script>标记和包含的JavaScript放在哪里合适的位置? I seem to recall that you are not supposed to place these in the <head> section, but placing at the beginning of the <body> section is bad, too, since the JavaScript will have to be parsed before the page is rendered completely (or something like that). 我似乎还记得您不应该将它们放在<head>部分中,但是放在<body>部分的开头也是不好的,因为必须在页面完全呈现之前对JavaScript进行解析(或类似的东西)。 This seems to leave the end of the <body> section as a logical place for <script> tags. 这似乎将<body>部分的结尾留作<script>标记的逻辑位置。

So, where is the right place to put the <script> tags? 所以,哪里把正确的地方<script>标记?

(This question references this question , in which it was suggested that JavaScript function calls should be moved from <a> tags to <script> tags. I'm specifically using jQuery, but more general answers are also appropriate.) (此问题引用了这个问题 ,在该问题中建议将JavaScript函数调用从<a>标记移至<script>标记。我专门使用jQuery,但更通用的答案也是合适的。)


解决方案:

参考一: https://stackoom.com/question/1pWt/我应该放在哪里-script-tags-in-HTML-markup
参考二: https://oldbug.net/q/1pWt/Where-should-I-put-script-tags-in-HTML-markup
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!