Home > Web Front-end > JS Tutorial > Example of using js to implement a message board (code provided)

Example of using js to implement a message board (code provided)

亚连
Release: 2018-05-18 16:12:46
Original
3388 people have browsed it

The following is an example of using js to implement a message board that I compiled for you. Interested students can take a look.

<!DOCTYPE html>  
<html>  
    <head>  
        <style>  
            #ly{  
                width:auto;  
                height: auto;  
            }  
        </style>  
        <meta charset="utf-8" />  
        <title></title>  
    </head>  
    <body>  
        <input type="text" id="tx" /><button value="留言" id="bt" >留言</button>  
        <div id="ly"></div>  
    <script>  
        var tx=document.getElementById("tx");  
        var ly=document.getElementById("ly");  
        var obt=document.getElementById("bt");   
        function tj(){  
            var oli =document.createElement("a");  
            oli.innerHTML=tx.value+&#39;删除&#39;+&#39;</br>&#39;;  
            oli.onclick=function ck(){  
                ly.removeChild(this);  
            }  
            oli.href="#";  
            if(ly.firstChild){  
                ly.insertBefore(oli,ly.firstChild);  
            }  
            else{ly.firstChild=oli;}  
            ly.appendChild(oli);  
        };  
        obt.onclick =function a(){tj();}  
    </script>  
    </body>  
</html>
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

JS operation DOM tree traversal method summary

##angularjsimplementation addition Shopping cart amount calculation function

JS implementation of array deduplication algorithm

The above is the detailed content of Example of using js to implement a message board (code provided). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template