Dynamically create table js files, JavaScript, Ajax, and DHTML, dynamically create tables, dynamically read files in XML, and read examples of DOM nodes.

Source: Internet
Author: User

Testdom. jsp file

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Title> testdomajax.html </title>
 
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Style type = "text/CSS">
# TD1 {color: red; font-size: 30px ;}

</Style>
<SCRIPT type = "text/JavaScript">
VaR XMLHTTP;
Function createxmlhttprequest (){
If (window. XMLHttpRequest)
{
XMLHTTP = new XMLHttpRequest ();
} Else if (window. activexobject)
{
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
}
Function startrequest (){
Createxmlhttprequest ();

Window. Status = '';
Url = "domxml. xml ";
XMLHTTP. Open ("get", URL, true );
XMLHTTP. onreadystatechange = testdom;
XMLHTTP. Send (null );
}

Function testdom (){
If (XMLHTTP. readystate = 4)
{
If (XMLHTTP. Status = 200 | XMLHTTP. Status = 0)
{
Restext = XMLHTTP. responsexml;
// Alert (restext );
VaR cmdles = restext. getelementsbytagname ("property ");
Alert (minutes Les. Length );
For (VAR I = 0; I <Les. length; I ++ ){
// All user names and genders are displayed cyclically
Alert (events les [I]. getelementsbytagname ("name") [0]. firstchild. nodevalue );
Alert (events les [I]. getelementsbytagname ("sex") [0]. firstchild. nodevalue );
}

VaR pro = cmdles [0]. childnodes;
For (VAR I = 0; I <pro. length; I ++ ){
VaR temp = pro [I]. childnodes;
For (var k = 0; k <temp. length; k ++ ){

}

}
// Alert (
// Alert (restext. getelementsbytagname ("property") [0]. childnodes [0]. nodevalue );
VaR pro = restext. getelementsbytagname ("property ");

If (PRO [0]. haschildnodes () = true ){
If (PRO [0]. childnodes [0]. haschildnodes () = true ){
VaR A = pro [0]. childnodes [0];
// Alert (A. firstchild. nodevalue );
If (A. haschildnodes () = true ){
// Alert (true + "1 ");
} Else {
Alert (false + "1 ");
}
} Else {
Alert ("false ");
}
} Else {
Alert ("false ");
}
//////////////////////////////////////// ////////
//// Parse the DOM tree node
//////////////////////////////////////// ///////
VaR P = restext. getelementsbytagname ("love ");
// Alert (P [0]. childnodes [0]. firstchild. nodevalue );
// Alert (P [0]. nextsibling. childnodes [0]. nodevalue );
// Alert (P [0]. childnodes [0]. nextsibling. childnodes [0]. nodevalue );

// Alert (P [0]. childnodes [0]. lastchild. nodevalue );
// Name
VaR P = restext. getelementsbytagname ("name ");
// Alert (P [0]. firstchild. nodevalue + "1 ");
// Alert (P [0]. lastchild. nodevalue + "2 ");
// Alert (P [0]. childnodes [0]. nodevalue + "3 ");
// Alert (P [1]. getattribute ("value") + "4 ");


}
}
}
VaR I = 1;
// Dynamically create a tree node. Table dom
Function createnode (){
VaR body = Document. getelementbyid ("body1 ");
VaR DV = Document. getelementbyid ("message ");
VaR table = Document. createelement ("table ");
VaR tbody = Document. createelement ("tbody ");
// Set node attributes.
Table. setattribute ("border", "1 ");
VaR TR = Document. createelement ("TR ");
VaR TD1 = Document. createelement ("TD ");
VaR td3 = Document. createelement ("TD ");
Td1.setattribute ("ID", "TD1 ");
VaR td2 = Document. createelement ("TD ");
// Add static text information.
VaR txt1 = Document. createtextnode ("name ");
VaR txt2 = Document. createtextnode ("gender ");
VaR txt3 = Document. createtextnode ("no." + I );

Td1.appendchild (txt1 );
Td2.appendchild (txt2 );
Td3.appendchild (txt3 );
Tr. appendchild (TD1 );
Tr. appendchild (td2 );
Tr. appendchild (td3 );
Tbody. appendchild (TR );
Table. appendchild (tbody );
Body. appendchild (table );
I = I ++;
// Document. Write (table );
}
 
 
</SCRIPT>

</Head>

<Body id = "body1">
<Form name = "from1" method = "get">
<Input type = "button" value = "button" onclick = "startrequest ();"/>

<Input type = "button" value = "createnode" onclick = "createnode ();"/>
</Form>
<Table border = 1>
<Tr>
<TD id = "TD1"> Zhai </TD>
<TD> sadfadsf </TD>
<TD> Zhai </TD>

</Tr>
</Table>
<Div id = "message"> </div>
</Body>
</Html>

 

 

// Testxmlajax

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Title> testxmlajax.html </title>
 
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">

<! -- <LINK rel = "stylesheet" type = "text/CSS" href = "./styles.css"> -->
<SCRIPT type = "text/JavaScript">
VaR XMLHTTP;
Function createxmlhttprequest (){
If (window. XMLHttpRequest)
{
XMLHTTP = new XMLHttpRequest ();
} Else if (window. activexobject)
{
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}

}

Function startrequest (){
Createxmlhttprequest ();

Window. Status = '';
Url = "testxml. xml ";
XMLHTTP. Open ("get", URL, true );
XMLHTTP. onreadystatechange = testinnerhtml;
XMLHTTP. Send (null );
}

Function testinnerhtml (){
If (XMLHTTP. readystate = 4)
{
If (XMLHTTP. Status = 200 | XMLHTTP. Status = 0)
{
Restext = XMLHTTP. responsetext;
VaR DIV = Document. getelementbyid ("message ");
Div. innerhtml = restext;

}
}
}
 
</SCRIPT>
</Head>

<Body>
<Form name = "from1" method = "get">
<Input type = "button" value = "button" onclick = "startrequest ();"/>

</Form>

<Div id = "message"> </div>
</Body>
</Html>

 

 

///// Domxml. xml

<? XML version = "1.0" encoding = "UTF-8"?>
<XML-body>
<Properties>
<Property>
<Name value = "username"> zhaizhanpo11 </Name>
<Sex> male </sex>
& Lt; password & gt; 123456 & lt;/password & gt;
<Love>
<Love1> football </love1>
<Love1> basketball </love1>
<Love1> Table Tennis </love1>
</Love>
<Tel> 13810116246 </Tel>
</Property>

<Property>
<Name value = "luzhongtao"> luzhongtao </Name>
<Sex> female </sex>
& Lt; password & gt; 123456 & lt;/password & gt;
<Love>
<Love1> football </love1>
<Love1> basketball </love1>
<Love1> Table Tennis </love1>
</Love>
<Tel> 13511110000 </Tel>
</Property>
</Properties>
</XML-body>

 

 

/// Textxml. xml

 

 

<? XML version = "1.0" encoding = "UTF-8"?>
<XML-body>
<Table>
<Tbody>
<Tr>
<TH> usrname </Th>
<TH> password </Th>
<TH> usersex </Th>
</Tr>

<Tr>
<TD> zhaizhanpo </TD>
<TD> zhaizhanpo </TD>
<TD> male </TD>
</Tr>

<Tr>
<TD> luzhasdongtao </TD>
<TD> luzhasdongtao </TD>
<TD> female </TD>
</Tr>

<Tr>
<TD> zhaizhasdanpo </TD>
<TD> zhaizasdasdhanpo </TD>
<TD> male </TD>
</Tr>

<Tr>
<TD> luzhoaaangtao </TD>
<TD> luzhoassngtao </TD>
<TD> female </TD>
</Tr>

<Tr>
<TD> zhaizhddffanpo </TD>
<TD> zhaizhanpo </TD>
<TD> male </TD>
</Tr>

<Tr>
<TD> luzhonddawdgtao </TD>
<TD> luzhongtao </TD>
<TD> female </TD>
</Tr>
</Tbody>
 
</Table>
</XML-body>

 

 

 

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.