开发者

html script tag

开发者 https://www.devze.com 2022-12-22 00:48 出处:网络
Why doesn\'t this work &开发者_开发知识库lt;script src=\"jquery.js\"/> But this works <script src=\"jquery.js\"></script>

Why doesn't this work

&开发者_开发知识库lt;script src="jquery.js"/>

But this works

<script src="jquery.js"></script>

?

Firefox 3.5.8


Because:

<script src="jquery.js"/>

is valid XML (including XHTML) but is not valid HTML.

See 18.2.1 The SCRIPT element:

18.2.1 The SCRIPT element

<!ELEMENT SCRIPT - - %Script;          -- script statements -->
<!ATTLIST SCRIPT
  charset     %Charset;      #IMPLIED  -- char encoding of linked resource --
  type        %ContentType;  #REQUIRED -- content type of script language --
  src         %URI;          #IMPLIED  -- URI for an external script --
  defer       (defer)        #IMPLIED  -- UA may defer execution of script --
  >

Start tag: required, End tag: required


The script element is not defined as EMPTY (since you can embed the script directly inside it), therefore in HTML the end tag is required, therefore you cannot have something that is (in tag soup terms) a start tag with a random / character in it representing the entire element.

Hence we have: http://www.w3.org/TR/xhtml-media-types/#C_2

0

精彩评论

暂无评论...
验证码 换一张
取 消