This article shares the specific code of JavaScript to implement the message board for your reference. The specific content is as follows Effect: Code: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> #txt2{ width:400px; height:50px; margin-top:5px; } #span1{ margin-left:200px; } #box{ width:400px; /*height:400px;*/ /*border:1px solid gray;*/ } #box .item{ height:80px; border-bottom:dashed 1px lightgrey } #box .c1{ height:30px; } #box .c1 span{ float:left; } #box .c1 a{ float:right; margin-right:20px; text-decoration: none; color:black; } </style> </head> <body> <div> Say something... </div> <div> <input type="text" placeholder="Hong Qigong" id="txt1"/> </div> <div> <textarea name="" id="txt2" maxlength="10"></textarea> </div> <div id="div3"> <span id="span1">You can also enter <span id="span2">10</span> characters</span> <input type="button" value = "Publish" id="btn"/> </div> <div> <div>Everyone is talking</div> </div> <div id="box"> <div class = "item"> <div class = "c1"> <span>Qiao Feng:</span> <span>Today............</span> <a href = "#">Delete</a> </div> <div>01 January 4th 01:28</div> </div> <div class = "item"> <div class = "c1"> <span>Qiao Feng:</span> <span>Today............</span> <a href = "#">Delete</a> </div> <div>01 January 4th 01:28</div> </div> </div> </body> <script type="text/javascript"> //Get the button var btn = document.getElementById("btn"); var box = document.getElementById("box"); var txt1 = document.getElementById("txt1"); var txt2 = document.getElementById("txt2"); btn.onclick = function () { //console.log(this); var divItem = document.createElement("div"); divItem.className = "item"; //box.appendChild(divItem);//Append nodebox.insertBefore(divItem, box.firstChild);//Insert nodevar div1 = document.createElement("div"); div1.className = "c1"; var div2 = document.createElement("div"); divItem.appendChild(div1); divItem.appendChild(div2); //Set the content of the first div var span1 = document.createElement("span"); div1.appendChild(span1); span1.innerHTML = txt1.value + " : "; var span2 = document.createElement("span"); div1.appendChild(span2); span2.innerHTML = txt2.value; var a = document.createElement("a"); a.href = "#"; a.innerHTML = "delete"; div1.appendChild(a); //a's deletion event a.onclick = function () { this.parentNode.parentNode.remove(); } var date = new Date(); //var str = date.toLocaleString(); var m = date.getMonth() + 1; var d = date.getDate(); var h = date.getHours(); var m2 = date.getMinutes(); m = fun1(m); d = fun1(d); h = fun1(h); m2 = fun1(m2); var str = m + "month" + d + "day" + h + ":" + m2; div2.innerHTML = str; } //Encapsulate a date formatting function function fun1(x) { if (x < 10) { return "0" + x; } return x; } var span2 = document.getElementById("span2"); txt2.onkeyup = function () { var str = this.value; console.log(str.length); span2.innerHTML = 10 - str.length; } </script> </html> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: JavaScript to implement click to switch verification code and verification
>>: Implementing carousel with native JavaScript
1. Parent div defines pseudo-classes: after and z...
Table of contents Docker-Maven-Plugin Maven plugi...
MySQL and connection related timeouts Preface: To...
Many people have read this book: "Grow as a ...
Preface Many years ago, I was a newbie on the ser...
Large Text Data Types in Oracle Clob long text ty...
This article example shares the specific code of ...
Designing navigation for a website is like laying...
ERROR 1290 (HY000) : The MySQL server is running ...
The implementation principle of chain programming...
1: Install SVN yum install -y subversion 2. Creat...
Table of contents Enter the topic mysql add, dele...
This article shares the specific code for using j...
Preface In front-end programming, we often use th...
These two attributes are often used, but their di...