解决方法
type="text/javascript"
This attribute is optional. Since
Netscape 2,the default programming
language in all browsers has been
JavaScript. In XHTML,this attribute
is required and unnecessary. In HTML,
it is better to leave it out. The
browser knows what to do.
W3C did not adopt the
language
attribute,favoring instead atype
attribute which takes a MIME type.
Unfortunately,the MIME type was not
standardized,so it is sometimes
"text/javascript"
or
"application/ecmascript"
or something
else. Fortunately,all browsers will
always choose JavaScript as the
default programming language,so it is
always best to simply write<script>
.
It is smallest,and it works on the
most browsers.
仅为娱乐目的,我试用了以下五个脚本
<script type="application/ecmascript">alert("1");</script> <script type="text/javascript">alert("2");</script> <script type="baloney">alert("3");</script> <script type="">alert("4");</script> <script >alert("5");</script>
在Chrome上,所有脚本3(type =“baloney”)都工作。 IE8没有运行脚本1(type =“application / ecmascript”)或脚本3.基于我的两个浏览器的非广泛的示例,它看起来像你可以安全地忽略type属性,但它使用它你最好使用一个法律(依赖浏览器)值。