< script>所需的'type'属性是必需的标签? [英] Is the 'type' attribute necessary for <script> tags?
问题描述
我看到了这两个:
< script src ='http://ajax.googleapis.com/ AJAX /库/ jquery的/ 1.4 / jquery.min.js'>< /脚本>
与此:
< script type ='text / javascript'src ='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'>< / script>
类型属性是否以任何方式出现问题?
对于 HTML 4.x ,类型
属性是必需的。 ( W3 ):
该属性指定元素内容的脚本语言并覆盖默认的脚本语言。脚本语言被指定为内容类型(例如text / javascript)。作者必须为此属性提供值。 对于 HTML 5 ,它是可选的即可。如果未指定,则默认为
text / javascript
。 ( W3 ):
type属性给出脚本的语言或数据的格式。如果该属性存在,则其值必须是有效的MIME类型。不得指定charset参数。如果该属性不存在,则使用默认值text / javascript。
I've seen both this:
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
and this:
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
Does the type attribute matter in any way?
解决方案For HTML 4.x, the
type
attribute is required. (W3):This attribute specifies the scripting language of the element's contents and overrides the default scripting language. The scripting language is specified as a content type (e.g., "text/javascript"). Authors must supply a value for this attribute. There is no default value for this attribute.
For HTML 5, it is optional. If it is not specified, it defaults to
text/javascript
. (W3):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".
这篇关于< script>所需的'type'属性是必需的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!