【发布时间】:2012-12-29 00:04:58
【问题描述】:
可能重复:
Where to place Javascript in a HTML file?
Should I write script in the body or the head of the html?
我一直在想,主要是因为我在创建页面时总是遇到麻烦,基于以下几点:
你什么时候写你的javascript
- 在
<head> - 在
<body> - 带有
$(document).ready()
我可能很愚蠢,但我有几次因为错误的位置或是或否 doc.ready() 命令而没有执行我的 JavaScript (/jQuery)。所以我真的很想知道。
同样适用于 jQuery 和 'var' 命令
【问题讨论】:
-
嗯,
var和其他人完全不一样…… -
对Pointy来说,我已经看到头部和身体也写了[var],所以我想知道是否有任何区别。 Mark Schultheiss,我问的是差异,而不是一段脚本应该在头部还是身体中。这有点不同。不过,谢谢。
标签: javascript jquery location head document-body