Document directory
InnerHtml usage
<Html>
<Head>
<Script>
Function Test (){
Var str = "";
Str + = "Hello ,";
Str + = "This is a Test! <Br/> ";
Str + = "I Love you; <br/> ";
Str + = "I Love you, too! ";
P. innerHTML = str + "<br/>" + Math. random ();
SetTimeout ('test (); ', 1000 );
}
</Script>
</Head>
<Body onload = Test ();>
<Span id = "p"> </span>
</Doby>
</Html>
InnerHTML refers to all html content contained in the div, and innerText refers to the text content contained in the div and displayed on the page. outerHTML includes more div TAG content than innerHTML. There is no difference between outerText and innerText.
Differences between innerTEXT and innerHTML:
Use innerHTML with caution
Recently I am working on AJAX and want to use javascript to implement the DataList function. I encountered a difficult problem. Because the HTML to be generated is very long, I wrote it as follows:
List. innerHTML = "<table> <tr> ";
List. innerHTML + = "<td>"
......
However, the innerHTML generated in this way is always incorrect. After studying for a long time, it turns out that innerHTML is a ghost. innerHTML comes with the syntax check function, which will automatically complete the incomplete HTML code. run the following test code to find out.
Document. getElementById ("AlbumList"). innerHTML = "<table> <tr> ";
Alert (document. getElementById ("AlbumList"). innerHTML );
He will automatically add the <tbody> and </tr> </table> tags in my code. Amazing !!!
One way to prevent him from filling in automatically is to use an intermediate variable:
Var html = "<table> <tr> ";
Html + = "<td> ";
......
List. innerHTML = html;
In this way, the problem can be solved.