Are Type Attributes on SCRIPT, STYLE, and LINK elements still needed?

前端 未结 4 487
时光取名叫无心
时光取名叫无心 2021-01-12 02:41

You will see many sites with the following type of code:

Script elements:



        
4条回答
  •  没有蜡笔的小新
    2021-01-12 03:37

    Short answer

    No, they aren't.

    Long answer

    For a long time, browser sets the default type=text/javascript at script elements, ect. when you omitted the type attribute. HTML5 makes this official, but every browser supported it long time ago.

    In fact, which doctype you use isn't affecting the browsers behaviour, only the W3C specs. The nice and short HTML5 doctype is the standard doctype for years in normal browsers. HTML5 just makes those nice things official.

    So you can use it and no browser will scream or fail, only the validator.

提交回复
热议问题