删除类型=“文本/ JavaScript”语言=“JavaScript”[复制]

Justin EthierPositiveGuy提出了一个问题:Leaving out type=“text/javascript” language=“javascript” [duplicate],或许与您遇到的问题类似。

回答者Nick Craver给出了该问题的处理方式:

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).

希望本文对你有帮助,欢迎支持JavaScript中文网


公众号

欢迎 JavaScript 爱好者