<脚本>标记vs< script type ='text / javascript'>标签 [英] <script> tag vs <script type = 'text/javascript'> tag

查看:89
本文介绍了<脚本>标记vs< script type ='text / javascript'>标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道,

 < script>的区别是什么? 

 < script type ='text / javascript'> 

不同的网络服务器有什么不同?



例如(我知道从w3schools提供一个链接是不正确的,但看起来)



http://www.w3schools.com/js/tryit.asp?filename=tryjs_myfirst



使用chrome,我访问了w3schools,并且意识到< script> 标签是我需要的。



然而,当我做了一个离线javascript测试时,我意识到我需要

 < script type ='文本/ JavaScript的'> 

标记。为什么会这样?

解决方案


在HTML 4中,type属性是必需的。根据我的经验,如果缺少
浏览器的所有默认文本/ javascript,但
行为并未在任何地方定义。虽然你理论上可以把它
拿出来,并假设它会被解释为JavaScript,但它不是
HTML,所以为什么不加它呢。



在HTML 5中,type属性是可选的,默认为
text / javascript


使用< ; script type =text / javascript> 或简单地< script> (如果省略,则类型相同)。不要使用< script language =JavaScript> ;语言属性已弃用



引用

http://social.msdn。

>
< script>之间的区别标记类型和<脚本>没有类型?



您是否需要type属性?



我使用HTML5-否



我没有使用HTML5 - 是


I was just wondering, what is the difference between

<script>

and

<script type = 'text/javascript'>

Is it different for different webservers?

For example,(I know it's incorrect to provide a link from w3schools, but look)

http://www.w3schools.com/js/tryit.asp?filename=tryjs_myfirst

Using chrome, I visited w3schools and I realised that the <script> tag is all I need.

However, when I did an offline javascript test, i realised that i need the

<script type = 'text/javascript'>

tag. Why is this so?

解决方案

In HTML 4, the type attribute is required. In my experience, all browsers will default to text/javascript if it is absent, but that behaviour is not defined anywhere. While you can in theory leave it out and assume it will be interpreted as JavaScript, it's invalid HTML, so why not add it.

In HTML 5, the type attribute is optional and defaults to text/javascript

Use <script type="text/javascript"> or simply <script> (if omitted, the type is the same). Do not use <script language="JavaScript">; the language attribute is deprecated

Ref :
http://social.msdn.microsoft.com/Forums/vstudio/en-US/65aaf5f3-09db-4f7e-a32d-d53e9720ad4c/script-languagejavascript-or-script-typetextjavascript-?forum=netfxjscript
and
Difference between <script> tag with type and <script> without type?

Do you need type attribute at all?

I am using HTML5- No

I am not using HTML5 - Yes

这篇关于&LT;脚本&GT;标记vs&lt; script type ='text / javascript'&gt;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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