请问下JavaScript的问题
发布网友
发布时间:2022-04-23 20:44
我来回答
共2个回答
热心网友
时间:2023-09-05 23:07
看下W3C的DOCUMENTATION
type在XHTML 1.0的正确写法:
<script type="text/javascript">
<![CDATA[
... unescaped script content ...
]]>
</script>
type在HTML 4.0的正确写法:
<script type="text/javascript">
... unescaped script content ...
</script>
而language只能在HTML 1.0-4.0的写法
<script language="JavaScript">
... unescaped script content ...
</script>
W3C关于HTML 4.0的DOCUMENTATION(http://www.w3.org/TR/html401/interact/scripts.html)需要翻译, 叫我补充
这个是TYPE:
type = content-type [CI]
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.
这个是LANGUAGE:
language = cdata [CI]
Deprecated (过时了). This attribute specifies the scripting language of the contents of this element. Its value is an identifier for the language, but since these identifiers are not standard, this attribute has been deprecated in favor of type.
language主要适合于早期一些浏览器(现在的浏览器也能用), 但那些浏览器现在已经基本没人用了...
所以写type(社和于现今所有浏览器)比较好, 因为type是W3C的最新标准.
热心网友
时间:2023-09-05 23:08
type是w3c的标准声明, language 是早期的声明方式,
为了脚本兼容,一般两个都写上