Start to study Ajax. Day 1

Source: Internet
Author: User

Start to study Ajax. Day 1

First of all, I am not suitable for learning programs, and I do not like it, because I am very careless, and every time I write a lot of code wrong. But out of love for DOM, JS, and CSS, I began to study Ajax.

What Is Ajax?
A: First, the four components of Ajax are [XMLHttpRequest], [Javascript], [DOM], and [CSS]. These four elements are not explained at the moment. [XMLHttpRequest] is responsible for communicating with the Web server. [Javascript] controls the page by controlling [DOM] and [CSS] performs page modification, of course, it is also a controlled object. This is Ajax. What I understand.

The following is an instance!
Hello pages of Ajax! Hello The World!

CODE: [Copy to clipboard] <Head>
<Title> Hello. the World </title>

<Style type = "text/css"> <! --
. Declared {color: red; font-size: 14px ;}
. Programmed {color: blue; font-size: 12px; font-weight: bold ;}
--> </Style>

<Script>
Window. onload = function (){
Var hello = document. getElementById ('hello'); // locate the element by ID
Hello. className = 'clared ';

Var empty = document. getElementById ('empty ');
AddNode (empty, "reader ");
AddNode (empty, "Ajax in Action! ");

Var children = empty. childNodes;
For (var I = 0; I <children. length; I ++ ){
Children [I]. className = 'grammed ';
}

Empty. style. border = 'solid green 2px '; // set the style for the node directly.
Empty. style. width = "200px ";
}

Function addNode (el, text ){
Var childEl = document. createElement ("div"); // create a new element
El. appendChild (childEl );
Var txtNode = document. createTextNode (text); // create a text element
ChildEl. appendChild (txtNode );
}
</Script>
</Head>
<Body>
<P id = "hello"> Hello </p>
<Div id = "empty"> </div>
</Body>
</Html> in this example, the DOM is controlled by Javascript, And the content written on the page is also modified by CSS.

Related Article

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.