我在某处读到您不再需要 type="text/javascript"
之类的东西和奇怪的CDATA
和 <!--
脚本标签中的内容。所以,而不是:
<script type="text/javascript">
//<![CDATA[
<!--
//your script here
-->
//]]>
</script>
你会这样做:
<script>
//your script here
</script>
我不记得我在哪里读到的。我认为它来自谷歌或雅虎工程师,他们特别提到了哪些浏览器需要这些古老的结构以及原因。任何人都知道这是讨论了什么博客文章/文章,或者有一个很好的资源来讨论这个?
最佳答案
见 Crockford's write-up on the <script>
tag ,最值得注意的是:
Do not use the
<!-- //-->
hack with scripts. It was intended to prevent scripts from showing up as text on the first generation browsers Netscape 1 and Mosaic. It has not been necessary for many years.<!-- //-->
is supposed to signal an HTML comment. Comments should be ignored, not compiled and executed. Also, HTML comments are not to include--
, so a script that decrements has an HTML error.
...
type="text/javascript"
此属性是可选的。从 Netscape 2 开始,所有浏览器的默认编程语言都是 JavaScript。在 XHTML 中,这个属性是必需的,也是不必要的。在 HTML 中,最好将其省略。浏览器知道该做什么。
关于javascript - 您是否需要在 <script> 标签中指定文本/javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5265202/