HTML Script tag: type or language (or omit both)?

前端 未结 3 1131
天涯浪人
天涯浪人 2020-11-22 11:20

vs.



        
3条回答
  •  孤独总比滥情好
    2020-11-22 12:00

    The language attribute has been deprecated for a long time, and should not be used.

    When W3C was working on HTML5, they discovered all browsers have "text/javascript" as the default script type, so they standardized it to be the default value. Hence, you don't need type either.

    For pages in XHTML 1.0 or HTML 4.01 omitting type is considered invalid. Try validating the following:

    
    
    
    
    
    
    
    

    You will be informed of the following error:

    Line 4, Column 41: required attribute "type" not specified

    So if you're a fan of standards, use it. It should have no practical effect, but, when in doubt, may as well go by the spec.

提交回复
热议问题