| Start to study Ajax. Day 1
First, I am not suitable for learningProgramPeople do not like it either, because I am very careless and every time I write a lot of errorsCode. 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] <HTML>
<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 through JavaScript, And the content written in the page is also modified with CSS for the page content.
|