Ajax basics-Chapter 2 (1)

Source: Internet
Author: User

Differences between innertext and innerhtml:

Example:

<Div id = "test">
<Span style = "color: Red"> test1 </span> Test2
</Div>

Test. innerhtml:

That is, all content from the starting position of the object to the ending position, including HTML tags.

In the preceding example, the value of test. innerhtml is "<span style =" color: Red "> test1 </span> Test2 ".

Test. innertext:

Content from the starting position to the ending position, but it removes the HTML Tag

In the preceding example, the value of text. innertext is "test1 Test2", in which the span tag is removed.

Difference between Div and Span:

DIV is block-elements (Block-level element), and span is inline-elements (intra-Row Element ). Another difference between them is that DIV will cause line breaks, while span will not.

Tbody:

The advantage of <tbody> is that the content between <tbody> </tbody> is displayed first,
Instead of displaying the entire table after it is downloaded,

Example:

Innerhtml.html

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> using responsetext with innerhtml </title>

<SCRIPT type = "text/JavaScript">
VaR XMLHTTP;

Function createxmlhttprequest (){
If (window. activexobject ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
}
}

Function startrequest (){
Createxmlhttprequest ();
XMLHTTP. onreadystatechange = handlestatechange;
XMLHTTP. Open ("get", "innerhtml. xml", true );
XMLHTTP. Send (null );
}

Function handlestatechange (){
If (XMLHTTP. readystate = 4 ){
If (XMLHTTP. Status = 200 | XMLHTTP. Status = 0 ){
Document. getelementbyid ("Results"). innerhtml = XMLHTTP. responsetext;
<! -- Document. getelementbyid ("Results"). innertext = XMLHTTP. responsetext; -->
}
}
}
</SCRIPT>
</Head>

<Body>
<Form action = "#">
<Input type = "button" value = "Search for today's activities" onclick = "startrequest ();"/>
</Form>
<Div id = "Results"> </div>
</Body>
</Html>

Innerhtml. xml:

<Table border = "1">
<Tbody>
<Tr>
<TH> activity name </Th>
<TH> location </Th>
<TH> time </Th>
</Tr>
<Tr>
<TD> waterskiing </TD>
<TD> dock #1 </TD>
<TD> 9: 00 am </TD>
</Tr>
<Tr>
<TD> volleyball </TD>
<TD> East Court </TD>
<TD> 2: 00 PM </TD>
</Tr>
<Tr>
<TD> hiking </TD>
<TD> trail 3 </TD>
<TD> 3: 30 pm </TD>
</Tr>
</Tbody>
</Table>

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.