admin管理员组文章数量:1313121
What is the difference between:
< script language="javascript" type="text/javascript">< /script>
< script type="text/javascript">< /script>
< script language="javascript">< /script>
What is the difference between:
< script language="javascript" type="text/javascript">< /script>
< script type="text/javascript">< /script>
< script language="javascript">< /script>
- See also: stackoverflow./questions/112482/… – Christian C. Salvadó Commented Jun 3, 2010 at 5:22
- Also see: stackoverflow./questions/2706290/… – Marcel Korpel Commented Nov 21, 2010 at 11:28
3 Answers
Reset to default 7All of them are technically deprecated, but the second annoys people least. :)
Both language (see W3C XHTML 1.1) and text/javascript are deprecated (see MIME registry for text). The remended mime type is application/javascript, but this is not backwards-patible.
Number 2 is the best you can do for now and for the foreseeable future.
First, the language
attribute is deprecated in the HTML 4.01 specification and the draft HTML 5 specification, and omitted from XHTML 1.0 Strict, so options 1 and 3 are out.
Second, do you need a type attribute at all? Yes. HTML 4.01 and XHTML 1.0 specifies the type
attribute as required while HTML5 has it as optional, defaulting to text/javascript
. Therefore until HTML5 is finalised and widely implemented, you must have the type
attribute if you want your HTML to be valid, which rules out the simple <script></script>
(I know this wasn't one of the original options, but it's something that I have seen remended).
Thirdly, what should go in the type attribute? As noted by Matthew Flaschen, the MIME type application/javascript
registered in 2006 is intended to replace text/javascript
. A quote from the relevant RFC:
This document thus defines text/javascript and text/ecmascript but marks them as "obsolete". Use of experimental and unregistered media types, as listed in part above, is discouraged. The media types,
* application/javascript * application/ecmascript
which are also defined in this document, are intended for mon use and should be used instead.
However, IE (up to and including version 8) doesn't execute script inside a <script>
element with a type
attribute of either application/javascript
or application/ecmascript
, so these are both unusable for the foreseeable future and we're stuck with text/javascript
.
<script language="javascript" type="text/javascript"></script>
HTML 4.01 / XHTML 1.0 Transitional with deprecated language attribute
<script type="text/javascript"></script>
HTML 4.01 / XHTML 1.0 Strict (or Transitional without deprecated language attribute)
<script language="javascript"></script>
HTML 3.2
本文标签: javascriptdifference bw ltscriptStack Overflow
版权声明:本文标题:javascript - difference bw <script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741932047a2405632.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论