语言= QUOT; JavaScript的"与type =“text / javascript” [英] language="javascript" vs. type="text/javascript"

查看:131
本文介绍了语言= QUOT; JavaScript的"与type =“text / javascript”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了将JavaScript添加到HTML中,我看到有人使用

 < script language = javascript> 

 < script type =text / javascript> 

似乎脚本是嵌入的还是外部的影响这个决定。



哪一个是首选的,为什么?

解决方案

< ;脚本语言=javascript> 曾用于非常旧的浏览器,并且已被弃用。

< script type =text / javascript> 是HTML 4标准。在HTML 5中, type 参数是可选的(JavaScript是默认的),所以你可以做< script>



作为一个整洁的黑客,如果您放置了一个无效的 type ,脚本将不会运行,但您仍然可以阅读JavaScript中的数据。一些模板库可以做到这一点。


For adding JavaScript to HTML, I have seen people use

<script language=javascript>

and

<script type="text/javascript">

It doesn’t seem like whether the script is embedded or external influences this decision.

Which one is preferred and why?

解决方案

<script language="javascript"> was used in very old browsers, and is deprecated.

<script type="text/javascript"> is the HTML 4 standard.

In HTML 5, the type parameter is optional (JavaScript is the default), so you can just do <script>.

As a neat hack, if you put an invalid type, the script won't be ran, but you can still read the data in JavaScript. Some template libraries do this.

这篇关于语言= QUOT; JavaScript的&QUOT;与type =“text / javascript”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆