This article mainly introduces how javascript uses DOM operations to implement simple message boards. It involves DOM operations in javascript and is very useful, for more information about how to use DOM in JavaScript to implement simple message boards, see the following example. Share it with you for your reference. The specific analysis is as follows:
Simple message board, that is, self-entertainment edition. To put it bluntly, it is to practice DOM operations.
Key Aspect 1: document. createElement ("tag name") New Element
Key Aspect 2: the parent element. appendChild ("element") inserts the newly created element into the tab of the page (in the last display of the tag) so that it will be displayed in the browser.
Key Aspect 3: parent element. insertBefore ("element", "before which element to insert") inserts the newly created element to the front of the tag specified in the page, so that the content entered later will display to the front.
Key Aspect 4: the parent element. removeChild ("element") deletes the specified element.
The Code is as follows:
Untitled documentScript window. onload = function () {var oMsg = document. getElementById ("msg"); var oBtn = document. getElementById ("btn"); var oMsg_c = document. getElementById ("msg_c"); var oUl = document. createElement ("ul"); oMsg_c.appendChild (oUl); oBtn. onclick = function () {var sVal = oMsg. value; var oli = document. createElement ("li"); oli. innerHTML = sVal + "delete"; var oli1 = oUl. getElementsByTagName ("li"); if (oli1.length> 0) {oUl. insertBefore (oli, oli1 [0]);} else {oUl. appendChild (oli);} oMsg. value = ''; var oSpan = document. getElementsByTagName ("span"); for (var I = 0; I
Simple message board
I hope this article will help you design javascript programs.
For more articles about how JavaScript uses DOM operations to implement simple message boards, refer to the PHP Chinese website!