Review DHTML(msdn):About Dynamic Content(1)
Changing HTML Content
Internet Explorer provides a set of properties and methods on each element that are designed to make it quite simple to change the document. There are four properties that provide the ability to see what's inside an element on the page and replace that content with new information: innerText, outerText, innerHTML, and outerHTML.
Assigning new text (also called a "string") to one of these properties replaces the contents of the element, including any elements contained by that element, with the new string.
<H1 id=myH1>Dynamic Content is Very Cool!</H1>
The content of the H1 can be changed with the innerText property.
document.all.myH1.innerText = "DHTML is Very Cool"
The H1 element remains in the document, while the content of the H1 changes to contain the new string "DHTML is Very Cool". The string assigned to innerText renders any HTML tags as text, and does not process the HTML. To insert HTML code into the contents of another element, you must use the innerHTML property.
document.all.myH1.innerHTML = "DHTML is <I>Very</I> Cool!"
The new string replaces the original content of the H1, and the word "Very" appears in italic.
The outerText and outerHTML properties represent the element itself, as well as the contents of the element. Assuming that the preceding example is contained by a body element, using an outerText property on the H1 replaces the entire element with the string attached. The following script causes the H1 to go away entirely, and the text string appears where the element was in the flow of the body's content.
document.all.myspan.outerText = "DHTML is VERY Cool!"
The outerHTML property replaces the element with rich HTML. Much like the example above where HTML was inserted in the H1, using the outerHTML property will do the same, except the H1 would also be removed.
document.all.myH1.outerHTML = "<SPAN STYLE='height:0;width:200;FILTER:Shadow(color=#00FF00)'>RICH HTML</SPAN>";
浙公网安备 33010602011771号