Review DHTML(msdn):About Dynamic Content(2)

Adding Document Content

The properties described above replace the entire contents of an element with a new string. What if you only want to insert new text or HTML and don't want to change what is already in the document? There are two helper methods on most elements that help you do just this.

These methods, insertAdjacentHTML and insertAdjacentText, place the new content at the beginning or end of the element, leaving the existing content intact. These methods all take a parameter that indicates one of four possible places the new content can be inserted with regard to the element: BeforeBegin, AfterBegin, BeforeEnd, and AfterEnd.

Can't put invalid HTML in the document: You cannot assign a string to innerHTML or outerHTML that contains invalid HTML. For example, trying to replace the content of the p element with another p will fail. A p element can only contain text and inline elements. However, replacing the entire p element with another p would work just fine.

Which Elements Will This Work For?

Only elements that appear in the BODY of the document can be changed with these properties. You can replace the contents of the BODY, but you can't replace the BODY itself.

The contents of a
td can be changed (innerText and innerHTML) and the table element itself can be replaced (outerText and outerHTML), but no other table elements and their contents can be changed with these properties.

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/dhtml_node_entry.asp

posted on 2004-08-06 16:04  9yue  阅读(445)  评论(0)    收藏  举报