What are the new features and tags of HTML5? Share new features of HTML5 JS

php是最好的语言
Release: 2018-07-30 15:51:04
Original
2270 people have browsed it

Since the introduction of H5, everyone only remembers html5. Has html4 been forgotten? Indeed, html5 is powerful and has many uses. It is of great significance to the Web. It can transform the existing content on the Web. Various problems are solved together, so this article will introduce the new features of HTML5 in detail. apache php mysql

begin!

1. HTML5 and HTML4

1.1 Reasons and goals for launch

The emergence of H5 is of great significance to the Web. Because his intention is to solve all kinds of problems currently existing on the Web.

  1. The compatibility between web browsers is very low

  2. The document structure is not clear enough (a lot of structures and semantic tags are added)

  3. The functions of Web applications are limited

The emergence of H5 has greatly solved the above problems

1.2 Syntax changes

1.2.1 DOCTYPE declaration

H5 The declaration of DOCTYPE is like this:

     <!DOCTYPE html>
Copy after login

Html:4s The declaration of DOCTYPE is like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Copy after login

Html: The declaration of 4t DOCTYPE is like this

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Copy after login

1.2.2 Specify character encoding

H5The specified character encoding format is as follows:

    <meta charset="UTF-8" />
Copy after login

Html :4s The specified character encoding is as follows:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
Copy after login

1.2.3 You can omit the element of the closing tag

Let me give you a simple example to understand what is going on
We usually write the p tag as It is written like this:

  <body>
  <p>Hello  world!</p>
  </body>
Copy after login

The new way of writing can be written like this:

    <body>
    <p/>Hello world!
    </body>
Copy after login

If you don’t believe it, you can test it yourself. How to test it? It's very simple, just set their styles separately and see if they are the same. If they are the same, it proves that the two are equivalent! Note: Set the style of p tag.

1.2.4 Attributes with boolean values ​​(disabled, checked)

disabled is mostly used for input elements, button elements, option elements, etc., meaning whether to disable these elements. The usage is as follows:

The attribute value "disabled" can be replaced with any other word or even "enabled" (except "false"), because the attribute value "false" means the attribute is not enabled, and the attribute value "true" means it is enabled. Attributes. The button elements of the following code are in a disabled state:

    <input type="button" disabled="true" value="测试按钮">  
    <input type="button" disabled="123" value="测试按钮">  
    <input type="button" disabled=" " value="测试按钮">  
    <input type="button" disabled="any word" value="测试按钮">
Copy after login

The button elements of the following code are in an enabled state:

    <input type="button" disabled="false" value="测试按钮">  
    <input type="button" value="测试按钮">
Copy after login

checked usage is the same as disabled, so I won’t go into too much detail here!

1.2.5 Omit the quotation marks (the quotation marks can be omitted for the attribute value in the tag)

The way to write the attribute value before H5 is like this, take the src attribute of the img tag as an example:

    <body>
    <img src="What are the new features and tags of HTML5? Share new features of HTML5 JS" alt="">
    </body>
Copy after login

can currently be written like this:

    <body>
    <img sre = What are the new features and tags of HTML5? Share new features of HTML5 JS  alt = "">
    </body>
Copy after login

The results of both are the same. Images can be displayed normally

1.3 Newly added semantic tags

What is semantics?

Semanticization refers to using reasonable HTML tags and their unique attributes to format document content. In layman's terms, semantics means processing data and information so that machines can understand it. Semanticization

New semantic tags: Section, article, aside, header, hgroup, footer, nav, figure

Specific usage: Usage of new semantic tags

1.4 New "fancy" tag elements

video, audio, canvas, embed, mark, progress, meter, The editor will not introduce the usage of these tags such as time, ruby, rt, rp, wbr, command, details, datalist, datagrid, keygen, output, source, and menu

here. Just use Baidu directly. Generally it is not used much, just remember to have this thing. (May be used during interviews)

1.5 New input types

Email, url, number, range, DatePickers
Only a partial explanation is given here:

  1. number

    <input type="number" name="">
Copy after login

What are the new features and tags of HTML5? Share new features of HTML5 JS

  1. ##range

  2.  <input  type = "range" name = "">
    Copy after login

What are the new features and tags of HTML5? Share new features of HTML5 JS

The rest of the editor will not test it. If you are interested, you can test it!

1.6 Obsolete tags

  1. basefont, big, center, font, s, tt, u, etc. that can be replaced by CSS

  2. Frame framework is no longer used

  3. Elements supported by only some browsers

  4. Other deprecated elements

1.7 New global attributes

Global attributes refer to attributes that can be used for all tags

  • contentEditable attribute (specifies whether the content can be edited )

  •     <input type="text" name="name" contenteditable="true">
    Copy after login

What are the new features and tags of HTML5? Share new features of HTML5 JS

  • designMode attribute (this is used in js to enable all elements in the page to be in editable mode)

  •             window.onload = function() {
                document.designMode = "on";
            }
    Copy after login
  • hidden attribute

  • ##spellcheck attribute (new attribute provided by input and textarea, with syntax check)
  • tabindex attribute (let the label get focus)
      <a href="javascript:void(0);" tabindex="3">你好</a>
      <a href="javascript:void(0);" tabindex="2">hello world!</a>
      <a href="javascript:void(0);" tabindex="1">html5</a>
Copy after login

What are the new features and tags of HTML5? Share new features of HTML5 JS

二、新增的语义化标签

2.1 新增元素

  1. 页眉

主要用于页面的头部的信息介绍,也可用于板块头部

  1. 页脚

页面的底部 或者 版块底部

  1. 导航 (包含链接的的一个列表)

     <nav>
        <a href="#">链接1</a>
        <a href="#">链接2</a>
    </nav>
Copy after login
  1. 页面上的一个标题组合

        <hgroup>
                 <h1>旅游</h1>
                 <h2>上海</h2>
      </hgroup>
Copy after login
  1. 页面上的板块

用于划分页面上的不同区域,或者划分文章里不同的节

  1. 用来在页面中表示一套结构完整且独立的内容部分

可以用来呈现论坛的一个帖子,杂志或报纸中的一篇文章,一篇博客,用户提交的评论内容,可互动的页面模块挂件等

该元素标签可以包含与当前页面或主要内容相关的引用、侧边栏、广告、nav元素组,以及其他类似的有别与主要内容的部分

8.

用于对元素进行组合。一般用于图片或视频

  1. figure 的子元素,用于对figure的内容进行说明

    <figure>
<!-- (注意没有alt) -->
    <img  src="images/225.jpg"    style="max-width:90%" height="100px" / alt="What are the new features and tags of HTML5? Share new features of HTML5 JS" >
    <figcaption>薰衣草</figcaption>
</figure>
Copy after login

What are the new features and tags of HTML5? Share new features of HTML5 JS

2.2 讲解标签

  1. 强调独立性

  2. 强调分段,一般存在一个标题的

  3.     <section>
        <h1>CAR</h1>
        </section>
    Copy after login

    一般用于传统导航,侧边栏导航,页内导航、翻页导航

    1. 非主体结构标签

    Header 元素是一种具有引导和导航作用的结构元素,通常用来防止整个页面和页面内的一个内容区块的标题,但是也可以包含其他内容,例如数据、搜索表单或相关的logo图片。

    Footer元素可以作为其上层父级内容区或者一个根区块的脚注。Footer通常包含其相关区块的脚注信息,如作者、相关的阅读链接及其版权信息等

    Hgroup元素是将标题及其子标题进行分组的标签。Hgroup标签通常会将h1-h6标签进行分组。譬如一个内容区的标题及其子元素算一组。

    Address元素用来在文档中呈现联系信息,包括文档作者或文档维护者的名字、它们的网站链接、电子邮箱、真实地址、电话号码等。Address应该不只用来呈现电子邮箱或真实地址,还用来展示跟文档相关的联系人的所有联系信息。

    三、表单内新增的元素和属性

    3.1 form 小编俗解:在 表单外部的标签可以通过form属性进行链接

    eg:

        <form id="form1">
        <label for="man">MAN</label><input type="radio" id="man" name="sex">
        <input type="radio" id="woman" name="sex">
        </form>
        <label for="woman" form="form1">WOMAN</label>
    Copy after login

    What are the new features and tags of HTML5? Share new features of HTML5 JS

    3.2 formtarget 属性

    • _blank 在新窗口中打开。

    • _self 默认。在相同的框架中打开。

    • _parent 在父框架集中打开。

    • _top 在整个窗口中打开。

    3.3 autofocus 获取焦点

        <input type="text" name="">
        <input type="text" name="" autofocus="autofocus">
    Copy after login

    What are the new features and tags of HTML5? Share new features of HTML5 JS

    3.4 required 属性

    HTML5中新增的属性可以应用于大多数的输入标签上,在提交时,如果元素中内容为空白,则不允许提交,同时在浏览器中显示信息提示文字。看下面例子:

        <form>
        <input type="text" name="" autofocus="autofocus" required>
        <input type="submit" name="">
        </form>
    Copy after login

    What are the new features and tags of HTML5? Share new features of HTML5 JS

    3.5 placeholder 属性,用于显示文本未输入内容之前,

        <form>
        <input type="text" name="name" placeholder="请输入你的姓名">
        </form>
    Copy after login

    What are the new features and tags of HTML5? Share new features of HTML5 JS

    3.6 autoComplete 属性

        <form autocomplete="on">
        <input type="text" name="name" placeholder="请输入你的姓名" >
        </form>
    Copy after login

    What are the new features and tags of HTML5? Share new features of HTML5 JS

    3.7 pattern 属性

    该属性用于正则表达式。见下面小例子:

        <form>
        <input type="text" name="content" autocomplete="off" placeholder="请输入邮箱" pattern="\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}" >
        <input type="submit">
    </form>
    Copy after login

    What are the new features and tags of HTML5? Share new features of HTML5 JS

    3.8 小编有话说

    新增的表单属性和元素还有很多,在这里我只列举了一些较常用的属性和元素,至于剩余的部分,小伙伴们用到的时候网上搜索就行。好啦!这部分结束,继续下面的内容。

    四、新的Javascript选择器

    4.1 querySelector()

        <p id="box">Hello World!</p>
        <script type="text/javascript">
          var box = document.querySelector("#box");
          box.style.color = "red";
          box.style.fontSize = "24px";
          box.style.fontWeight = "blod";
        </script>
    Copy after login

    What are the new features and tags of HTML5? Share new features of HTML5 JS

    4.2 querySelectorAll()

        <p id="box">Hello World!</p>
        <p id="box">Hello!</p>
        <p id="box">World!</p>
        <script type="text/javascript">
          var boxList = document.querySelectorAll("#box");
          boxList.forEach(function(item){
              item.style.color = "red";
              item.style.fontSize = "24px";
              item.style.fontWeight = "blod";
          });
        </script>
    Copy after login

    What are the new features and tags of HTML5? Share new features of HTML5 JS

    五、新增 dom 节点属性

    clasList 中的属性和方法

    • length (长度)

        <p id="box" class="test  test1   test2  test 3 test4"></p>
        <script>
            var  box = document.querySelector("#box");
            window.onload = function (){
                console.log(box.classList);
                console.log(box.classList.length);
            }
        </script>
    Copy after login

    What are the new features and tags of HTML5? Share new features of HTML5 JS

    • add() 增加

        <p   id = "box"  class = "test  test1 test2 test3 test4 "></p>    
        <script>
            var box = document.querySelector("#box");
            window.onload = function(){
                box.classList.add("test5");
                console.log(box.classList);
            }
        </script>
    Copy after login

    What are the new features and tags of HTML5? Share new features of HTML5 JS

    • remove() 移除

        <p id="box" class="test test2 test3 test4">Hello World!</p>
    <script type="text/javascript">
        var box = document.querySelector("#box");
        window.onload = function (){
            box.classList.remove("test");
            console.log(box.classList);
        }
    </script>
    Copy after login

    What are the new features and tags of HTML5? Share new features of HTML5 JS