javascript - 我还需要使用类型 ='text/javascript' 吗?

标签 javascript jquery html dom

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/

相关文章:

python - 使用 BeautifulSoup 从本地保存的 html 文件中提取原始 html

javascript - 如何通过单击链接 javascript 提交表单

javascript - 从 JSON 响应创建对象并删除不需要的键值

javascript - 使用 RegExp 时出错 : Invalid left-hand side in assignment

javascript - 按钮组 Bootstrap 不起作用

javascript - 获取自定义属性的值

javascript - 响应头中的 Access-Control-Allow-Origin 是否区分大小写?

javascript - 没有 req.session.save() session 不会保存在 Node.js 中

javascript - 如何在满足条件时打破 CasperJS 的重复功能?

javascript - 在 Google 脚本中获取 url 后出现菱形字符(�)