Chapter 5 and chapter 6 of "proficient in JavaScript" (iii)

Source: Internet
Author: User

It is better to change the title to review, because there are a lot of knowledge points in the book, which is not easy to summarize. I would like to mention it and repeat the Code if I think it is important. To continue (2), delete a node from Dom: nodeparent. removechild (nodetoremove );

In the book, removechild encapsulates two functions:

// Remove a node from the DOM

Function remove (ELEM ){

If (ELEM) ELEM. parentnode. removechild (ELEM );

}

// Clear all child nodes of an element

Function empty (ELEM ){

While (ELEM. firstchild ){

Remove (ELEM. firstchild );

}

}

The Dom part is the end of the review, followed by the event part. It is also a core component of Javascript development. When it comes to events, there is an important concept. Javascript events are divided into two phases: Capturing and bubbling phase, which are called the capture and bubble phases of events.

Here is an example to illustrate the problem:

<Body>

<Div id = "content">

<Ul class = "Links">

<Li>

<A href = "/"> Home </a> // click this link.

</LI>

<Li> <a href = "/about/"> about </a> </LI>

</Ul>

</Div>

</Body>

First, capturing phase: Suppose we have clicked a link and the event trigger sequence is: the click Processing Event of the document --> the click Processing Event of the body -->

The DIV's click Processing Event finally reaches the we clicked, and then enters the bubbling phase. The order is the opposite to capturing phase.

Sometimes we want to cancel event bubbling:

Function stopbubble (e ){

// If the event object is input by default, this is not an IE browser

If (E & E. stoppropagation)

// Supports the W3C standard stoppropagation () method.

E. stoppropagation ();

Else

// Otherwise, we will use IE to cancel event bubbling.

Window. event. cancelbubble = true;

}

We should also pay attention to the default browser behavior during the development process. For example, when the user enters the content in a user form and presses the submit button, if the content of the form is incorrect, an error should be reported to the user and not submitted. Prevent the default behavior of the browser:

Function stopdefault (e ){

// Block default browser behavior (W3C)

If (E & E. preventdefault) E. preventdefault ();

Else window. event. returnvalue = false; // Method Used in IE

Return false;

}

Next, the author describes some principles for developing web pages. For example, if CSS and JavaScript are removed, check whether your web pages can be properly navigated and browsed, whether your HTML tag has good semantics, whether CSS and JavaScript are separated from HTML Dom, etc .. I think there is a good book on CSS, "beyond CSS: the essence of web design".

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.