Table of Contents
1. readyState attribute " > 1. readyState attribute
HTML code" > HTML code
JavaScript code" > JavaScript code
Preview effect
2. Compatibility mode judgment" > 2. Compatibility mode judgment
3. Head attribute" > 3. Head attribute
JavaScript code
Home Web Front-end H5 Tutorial HTML5 actual combat and analysis of HTMLDocument changes

HTML5 actual combat and analysis of HTMLDocument changes

May 25, 2017 pm 03:21 PM

I have previously introduced you to some of the new additions to HTML5, and I believe you all have some understanding of them. Today I will introduce to you the newly added content about HTMLDocument in HTML5. So what are the newly added contents about HTMLDocument in HTML5? The newly added contents about HTMLDocument in HTML5 include readyState attribute, compatibility mode judgment and head attribute. Let me introduce these newly added little things to you one by one.

1. readyState attribute

As early as the IE4 era, the document object introduced the readyState attribute, but it has never been included in the standard. Now, in HTML5 As time goes by, it has been incorporated into the norm. The readyState attribute has two possible values:

 (1) loading, the document is being loaded

 (2)complete, the document has been loaded

How to use document appropriately What about .readyState? The most appropriate way to use document.readyState is to use it to implement an indicator that the document has been loaded. Until this property is widely supported, implementing such an indicator will still require the onload event handler to set a label indicating that the document has been loaded. The following example is as follows

HTML code

<p>梦龙小站</p>
<p class="complete"></p>
Copy after login

JavaScript code

<script type="text/javascript">
window.onload = function(){
	var a = 0;
	var b = 0;
	if(document.readyState == "complete"){
		$(".complete").html( "加载好了" )
	}

	if(document.readyState == "loading"){
		$(".load").html( $(".load").html() + "<br/>" + a++ )
	}
};
Copy after login

Preview effect

HTML5 actual combat and analysis of HTMLDocument changes

2. Compatibility mode judgment

After IE6, it began to distinguish the modes of rendering pages, divided into standard and mixed, and detect the compatibility mode of the page. It becomes a necessary function of the browser. IE adds an attribute called compatMode to the document for this purpose. This attribute is to tell the developer which rendering mode the browser uses. As shown in the small example below, in standard mode, the value of document.compatMode is equal to "CSS1Compat", while in promiscuous mode, the value of document.compatMode is equal to "BackCompat".

JavaScript code

if(document.compatMode == "CSS1Compat"){
	alert("标准模式")
}else{
	alert("混杂兼容模式")
}
Copy after login

3. Head attribute

As a supplement to the body element of the document referenced by document.body, HTML5 adds a new document.head attribute, so that the head tag can be referenced. The usage method is as follows

JavaScript code

var head = document.head || document.getElementsByTagName("head")[0];
Copy after login

Make the compatibility as above. If it can be used, use document.head, otherwise still use the getElementsByTagName() method. The browsers supported by the document.head attribute are Chrome and Safari 5.

HTML5 actual combat and analysis of HTMLDocument changes (readyState attribute, compatibility mode and head attribute) are introduced here. Learn some new knowledge in the midst of your busy schedule. Life is still very fulfilling, and put your learning into practice. I would like to share some little things with you, it was such a magical day. Updates related to HTML5 practice and analysis.

【Related recommendations】

1. Free h5 online video tutorial

2. HTML5 full version manual

3. php.cn original html5 video tutorial

4. HTML5 game framework cnGameJS development record-detailed resource loading module code

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles