【发布时间】:2012-08-28 12:08:43
【问题描述】:
可能重复:
Why write <script type=“text/javascript”> when the mime type is set by the server?
我知道<script type='type/javascript'></script> 不再需要 type 属性了。我的问题是,我自己插入脚本的时候,还需要用吗?
var hello = document.createElement('script');
hello.type = 'text/javascript'; // still needed?
hello.async = true;
hello.src = 'http://mysite.com/script.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(hello);
我看到在 Google Analytics 中他们仍然使用它ga.type = 'text/javascript';,Disqus 也使用它和dsq.type = 'text/javascript';
那么,这有必要吗?
【问题讨论】:
-
AFAIK,从 HTML5 开始,不再需要。
-
你的意思是
type(type="text/javascript") 而不是src,这是必需的。
标签: javascript jquery html dom