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
Sometimes we may encounter such a requirement, th...
Table label composition The table in HTML is comp...
This article shares the specific code for JavaScr...
<br /> When we browse certain websites and s...
This article shares the MySQL 5.7 installation an...
Previous words Line-height, font-size, and vertica...
PSD to div css web page cutting example Step 1: F...
Preface This article mainly introduces the soluti...
1. Check whether the MySQL service is started. If...
This article uses an example to describe the erro...
Although the frequency of starting the shell is v...
Copy code The code is as follows: <thead> &...
1. Rendering2. Operation steps 1. Apply for Tence...
Dockerfile is a text file that contains instructi...
1. Delete the original mariadb, otherwise mysql c...