<i id='p3YAf'><tr id='p3YAf'><dt id='p3YAf'><q id='p3YAf'><span id='p3YAf'><b id='p3YAf'><form id='p3YAf'><ins id='p3YAf'></ins><ul id='p3YAf'></ul><sub id='p3YAf'></sub></form><legend id='p3YAf'></legend><bdo id='p3YAf'><pre id='p3YAf'><center id='p3YAf'></center></pre></bdo></b><th id='p3YAf'></th></span></q></dt></tr></i><div id='p3YAf'><tfoot id='p3YAf'></tfoot><dl id='p3YAf'><fieldset id='p3YAf'></fieldset></dl></div>

      <small id='p3YAf'></small><noframes id='p3YAf'>

      <tfoot id='p3YAf'></tfoot>
      • <bdo id='p3YAf'></bdo><ul id='p3YAf'></ul>

        <legend id='p3YAf'><style id='p3YAf'><dir id='p3YAf'><q id='p3YAf'></q></dir></style></legend>
      1. 有必要写 HEAD、BODY 和 HTML 标签吗?

        时间:2023-08-01
          1. <legend id='XU7YR'><style id='XU7YR'><dir id='XU7YR'><q id='XU7YR'></q></dir></style></legend>

            <i id='XU7YR'><tr id='XU7YR'><dt id='XU7YR'><q id='XU7YR'><span id='XU7YR'><b id='XU7YR'><form id='XU7YR'><ins id='XU7YR'></ins><ul id='XU7YR'></ul><sub id='XU7YR'></sub></form><legend id='XU7YR'></legend><bdo id='XU7YR'><pre id='XU7YR'><center id='XU7YR'></center></pre></bdo></b><th id='XU7YR'></th></span></q></dt></tr></i><div id='XU7YR'><tfoot id='XU7YR'></tfoot><dl id='XU7YR'><fieldset id='XU7YR'></fieldset></dl></div>

              <tfoot id='XU7YR'></tfoot>

                  <tbody id='XU7YR'></tbody>

                <small id='XU7YR'></small><noframes id='XU7YR'>

                • <bdo id='XU7YR'></bdo><ul id='XU7YR'></ul>
                  本文介绍了有必要写 HEAD、BODY 和 HTML 标签吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否需要写<html><head><body>标签?

                  比如我可以做这样一个页面:

                  For example, I can make such a page:

                  <!DOCTYPE html>     
                      <meta http-equiv="Content-type" content="text/html; charset=utf-8">
                      <title>Page Title</title>
                      <link rel="stylesheet" type="text/css" href="css/reset.css">
                      <script src="js/head_script.js"></script><!-- this script will be in head //-->
                  
                  
                  <div>Some html</div> <!-- here body starts //-->
                  
                      <script src="js/body_script.js"></script>
                  

                  Firebug 正确地分离了头部和身体:

                  And Firebug correctly separates head and body:

                  W3C 验证表明它是有效的.

                  W3C Validation says it's valid.

                  但我很少在网上看到这种做法.

                  But I rarely see this practice on the web.

                  有什么理由写这些标签吗?

                  Are there any reason to write these tags?

                  推荐答案

                  省略 htmlheadbody 标签 当然是 HTML 规范允许的.根本原因是浏览器一直在寻求与现有网页保持一致,而 HTML 的早期版本并没有定义这些元素.当 HTML 2.0 第一次这样做时,它是以一种在缺少标签时会被推断出来的方式完成的.

                  Omitting the html, head, and body tags is certainly allowed by the HTML specs. The underlying reason is that browsers have always sought to be consistent with existing web pages, and the very early versions of HTML didn't define those elements. When HTML 2.0 first did, it was done in a way that the tags would be inferred when missing.

                  我经常发现在原型设计时省略标签很方便,尤其是在编写测试用例时,因为它有助于将标记集中在有问题的测试上.推理过程应该完全按照您在 Firebug 中看到的方式创建元素,并且浏览器在这方面非常一致.

                  I often find it convenient to omit the tags when prototyping and especially when writing test cases as it helps keep the mark-up focused on the test in question. The inference process should create the elements in exactly the manner that you see in Firebug, and browsers are pretty consistent in doing that.

                  但是……

                  IE 在这方面至少有一个已知错误.甚至 IE9 也展示了这一点.假设标记是这样的:

                  IE has at least one known bug in this area. Even IE9 exhibits this. Suppose the markup is this:

                  <!DOCTYPE html>
                  <title>Test case</title>
                  <form action='#'>
                     <input name="var1">
                  </form>
                  

                  你应该(并且在其他浏览器中这样做)得到一个如下所示的 DOM:

                  You should (and do in other browsers) get a DOM that looks like this:

                  HTML
                      HEAD
                          TITLE
                      BODY
                          FORM action="#"
                              INPUT name="var1"
                  

                  但是在 IE 中你会得到这个:

                  But in IE you get this:

                  HTML
                      HEAD
                         TITLE
                         FORM action="#"
                             BODY
                                 INPUT name="var1"
                      BODY
                  

                  自己看吧.

                  此错误似乎仅限于任何文本内容和任何 body 开始标记之前的 form 开始标记.

                  This bug seems limited to the form start tag preceding any text content and any body start tag.

                  这篇关于有必要写 HEAD、BODY 和 HTML 标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么是&lt;center&gt;标签在 HTML 中已弃用? 下一篇:在&lt;option&gt;中使用href链接标签

                  相关文章

                    <tfoot id='F2Z0l'></tfoot>
                  1. <small id='F2Z0l'></small><noframes id='F2Z0l'>

                  2. <legend id='F2Z0l'><style id='F2Z0l'><dir id='F2Z0l'><q id='F2Z0l'></q></dir></style></legend>
                    <i id='F2Z0l'><tr id='F2Z0l'><dt id='F2Z0l'><q id='F2Z0l'><span id='F2Z0l'><b id='F2Z0l'><form id='F2Z0l'><ins id='F2Z0l'></ins><ul id='F2Z0l'></ul><sub id='F2Z0l'></sub></form><legend id='F2Z0l'></legend><bdo id='F2Z0l'><pre id='F2Z0l'><center id='F2Z0l'></center></pre></bdo></b><th id='F2Z0l'></th></span></q></dt></tr></i><div id='F2Z0l'><tfoot id='F2Z0l'></tfoot><dl id='F2Z0l'><fieldset id='F2Z0l'></fieldset></dl></div>
                      <bdo id='F2Z0l'></bdo><ul id='F2Z0l'></ul>