Possible Duplicate:
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';
一起使用
那么,这个有必要吗?
最佳答案
否,如果该属性不存在,则这是默认值:
来自specification :
The type attribute gives the language of the script or format of the data. If the attribute is present, its value must be a valid MIME type. The charset parameter must not be specified. The default, which is used if the attribute is absent, is "text/javascript".
关于javascript - 我还需要使用类型 ='text/javascript' 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12253199/