Dhtml|web| News | page
IE's DHTML object provides four read-write properties to dynamically manipulate the content of page elements: innertext, Outertext, InnerHTML, outerhtml.
Note two points:
1. The value of the Innertext,outertext property is rendered as plain text, even if it contains an HTML tag, and the innerHTML, outerHTML renders the text parsed by the HTML engine, It can react to the performance of HTML tags in attributes.
2. Assigning a value to an object's Outertext,outerhtml property (that is, a write operation) deletes the object.
The assignment of the above four attributes is only to replace the original object's text content, you want to specify the element-related position in the page add text content, you need to use the insertAdjacentHTML and insertAdjacentText methods. The form is as follows:
Object.insertadjacenttext (Swhere, Stext)
Object.insertadjacenthtml (Swhere, Stext)
Where Swhere represents the position of the inserted text relative to the HTML label, with the following four preset values:
Beforebegin,afterbegin,beforeend,afterend
The following points should be noted in use:
1. Both of these methods must be available after the entire document is loaded, or an error will occur.
2. insertAdjacentText can only insert plain text, insertadjacenthtml text inserted in HTML format
3. Insert a script with insertadjacenthtml, you must use the Defer property in the script element, otherwise a run-time error will occur
4. After insertadjacenthtml inserts an HTML element, all and other possible element collections are automatically updated to reflect dynamic changes. The Sourceindex properties of the subsequent elements of the page will change.
5. When you give an HTML tag that is not valid for the Inserthtml/outerhtml property, the method may have a run-time error. If the following code will be faulted:
In addition to the page content dynamic operation also need to note some of the following details:
1. Only the content displayed within the body of the document can be dynamically changed by the above properties and methods, the contents of the body object can be dynamically manipulated, but the body object itself cannot be replaced.
2. The above properties and methods cannot manipulate empty tags (HTML tags without content), such as input,img.
3. For table objects, only TD (Innerhtml/innertext) and table (Outerhmtl/outertext) objects can replace or insert content with certain properties, while other table objects, such as TR, Tbody cannot use these properties to change content.
Turn from: Dynamic Network production guide www.knowsky.com