Javascript method for implementing a simple message board using DOM operations _ javascript skills

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.