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

问题描述

我创建的大多数脚本标记都是在标记中包含 type =text / javascriptlanguage =javascript。但我的老板并没有。有时候他排除了这两种情况,有时甚至没有引号也只有 language = javascript >

现在我们还没有问题在任何带有标签的主流浏览器中。我正在谈论IE,FF,Safari和Chrome的所有版本。



个人而言,我觉得它很懒惰,只是完全不当和糟糕的编码习惯,即使它没有它,它也能正常工作。



任何人都知道是否应该包含这两者或者只包含一个,还是可以放弃ASP.NET?

解决方案

我想这应该是现在更新,景观已经改变了很多:



对于HTML5文档类型,不再需要。例如:我们将它从Stack Overflow的页面中删除。如果您使用的是HTML5文档类型,那么它是完全可选的,并且默认为 text / javascript ,所以您绝对可以在每个当前(甚至是非常旧的)浏览器。实际上,即使在HTML4中也是如此,虽然不是严格有效的HTML。



对于HTML4文档类型(有效),您需要它 。对于一个浏览器来说,它并不是真正需要的,并且表现得很好(这一直都是Netscape 2的事),但它不会是有效的HTML。如果你有一个HTML4的文档类型,那么保持它并保持有效 - 因为嘿,为什么不呢?




原始答案:

我会在所有当前浏览器中使用 type =text / javascript以保证安全在那里保存21个字符? 。



另外,任何验证器都会抛出一个错误,尽管它会可能在浏览器中工作(除非你正在处理 旧的东西)。


Most of the script tags I create, I always include type="text/javascript" language="javascript" in the tag. My boss however does not. Sometimes he excludes both, sometimes just has language=javascript even without the quotes

Now we have not had an issue in any of the major browsers with his tags. I'm talking about all versions of IE, FF, Safari, and Chrome.

Personally I feel it's laziness and just totally improper and bad coding practice to leave stuff out like this even if it works without it.

Anyone know if both should be included or just one or is it ok to leave both out in ASP.NET?

解决方案

I suppose this should be updated now that the landscape has changed quite a bit:

For an HTML5 doctype, it's no longer required. For example: we leave it out of the pages here at Stack Overflow. If you're using an HTML5 doctype then it's completely optional and defaults to text/javascript, so you're absolutely fine leaving it off in every current (or even very old) browser. Realistically, this was also true even in HTML4 though not strictly valid HTML.

For an HTML4 doctype (to be valid), you need it. For a browser to actually function, it's not strictly needed and will behave just fine (this has been true all the way back to Netscape 2) - but it won't be valid HTML. If you have an HTML4 doctype, then keep it around and be valid - cause hey, why not?


Original Answer:

I would use type="text/javascript" to be safe in all current browsers, why leave the ambiguity in there to save 21 characters? language="" however is deprecated, I'd leave it out.

Also, any validator is going to throw an error, though it will likely work inside the browser (unless you're dealing with something very old).

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

07-31 02:07