美文网首页HTML
[HTML] script标签的type属性

[HTML] script标签的type属性

作者: 何幻 | 来源:发表于2016-03-04 07:13 被阅读344次

    http://www.w3.org/TR/2014/REC-html5-20141028/scripting-1.html#attr-script-type

    (1)type attribute

    The type attribute gives the language of the script or format of the data. If the attribute is present, its value must be a valid MIME type. The charset parameter must not be specified. The default, which is used if the attribute is absent, is "text/javascript".

    (2)script block's type

    If either:
    the script element has a type attribute and its value is the empty string, or
    the script element has no type attribute but it has a language attribute and that attribute's value is the empty string, or
    the script element has neither a type attribute nor a language attribute, then
    ...let the script block's type for this script element be "text/javascript".

    Otherwise, if the script element has a type attribute, let the script block's type for this script element be the value of that attribute with any leading or trailing sequences of space characters removed.

    Otherwise, the element has a non-empty language attribute; let the script block's type for this script element be the concatenation of the string "text/" followed by the value of the language attribute.

    The language attribute is never conforming, and is always ignored if there is a type attribute present.

    (3)scripting language

    If the user agent does not support the scripting language given by the script block's type for this script element, then the user agent must abort these steps at this point. The script is not executed.


    其中:

    (1)valid MIME TYPE

    http://www.w3.org/TR/2014/REC-html5-20141028/infrastructure.html#valid-mime-type

    The term MIME type is used to refer to what is sometimes called an Internet media type in protocol literature. The term media type in this specification is used to refer to the type of media intended for presentation, as used by the CSS specifications.

    A string is a valid MIME type if it matches the media-type rule defined in section 3.1.1.1 "Media Types" of RFC 7231. In particular, a valid MIME type may include MIME type parameters.

    (2)Media Type

    http://tools.ietf.org/html/rfc7231#section-3.1.1

    3.1.1.1. Media Type

    HTTP uses Internet media types [RFC2046] in the Content-Type
    (Section 3.1.1.5) and Accept (Section 5.3.2) header fields in order
    to provide open and extensible data typing and type negotiation.
    Media types define both a data format and various processing models:
    how to process that data in accordance with each context in which it
    is received.

     media-type = type "/" subtype *( OWS ";" OWS parameter )
     type = token
     subtype = token
    

    The type/subtype MAY be followed by parameters in the form of
    name=value pairs.

     parameter = token "=" ( token / quoted-string ) 
    

    The type, subtype, and parameter name tokens are case-insensitive.
    Parameter values might or might not be case-sensitive, depending on
    the semantics of the parameter name. The presence or absence of a
    parameter might be significant to the processing of a media-type,
    depending on its definition within the media type registry.

    A parameter value that matches the token production can be
    transmitted either as a token or within a quoted-string. The quoted
    and unquoted values are equivalent. For example, the following
    examples are all equivalent, but the first is preferred for
    consistency:

     text/html;charset=utf-8
     text/html;charset=UTF-8
     Text/HTML;Charset="utf-8"
     text/html; charset="utf-8"
    

    Internet media types ought to be registered with IANA according to
    the procedures defined in [BCP13].

      Note: Unlike some similar constructs in other header fields, media
      type parameters do not allow whitespace (even "bad" whitespace)
      around the "=" character.

    相关文章

      网友评论

        本文标题:[HTML] script标签的type属性

        本文链接:https://www.haomeiwen.com/subject/kkunkttx.html