2
可能重複:
Why write <script type=「text/javascript」> when the mime type is set by the server?我還需要使用type ='text/javascript'嗎?
我知道<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);
我看到,在谷歌Analytics(分析),他們仍然使用它ga.type = 'text/javascript';
和Disqus與dsq.type = 'text/javascript';
所以用它爲好,這是需要的?
向後兼容性... – perilbrain
AFAIK,自HTML5起,不再需要它。 – 0x499602D2
當MIME類型由服務器設置時,爲什麼要寫