Defering javascript - what is the correct html syntax defer or defer=“defer”

前端 未结 4 713
别跟我提以往
别跟我提以往 2020-12-21 03:10

What is the correct syntax for using the defer attribute in your javascript?

I have seen it done two ways:

1:



        
4条回答
  •  一个人的身影
    2020-12-21 03:41

    defer is a boolean attribute [HTML 4.01 spec]:

    Some attributes play the role of boolean variables (e.g., the selected attribute for the OPTION element). Their appearance in the start tag of an element implies that the value of the attribute is "true". Their absence implies a value of "false".

    [...]

    In HTML, boolean attributes may appear in minimized form -- the attribute's value appears alone in the element's start tag. Thus, selected may be set by writing:

    instead of:

    Authors should be aware that many user agents only recognize the minimized form of boolean attributes and not the full form.

    However, if you use XHTML, you have to use the second form since XHTML follows XML syntax where attributes always have to have a value.

提交回复
热议问题