Native JavaScript message board

Native JavaScript message board

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:
  • JS realizes message board function
  • jsp message board source code three: for jsp beginners.
  • How to use DOM operations to implement a simple message board in js
  • JS+CSS simulates a message board instance that can display content without refreshing
  • JS realizes the message board function [floor effect display]
  • Foldable message board implemented by js (with source code download)
  • jsp message board source code 2: for jsp beginners.
  • My ajax message board source code good application js
  • Code example of writing a message board using ReactJS and Python's Flask framework
  • jsp message board source code 1: for jsp beginners.

<<:  JavaScript to implement click to switch verification code and verification

>>:  Implementing carousel with native JavaScript

Recommend

A complete guide to clearing floats in CSS (summary)

1. Parent div defines pseudo-classes: after and z...

Detailed usage of docker-maven-plugin

Table of contents Docker-Maven-Plugin Maven plugi...

Detailed summary of MySQL and connection-related timeouts

MySQL and connection related timeouts Preface: To...

Summary of the three stages of visual designer growth

Many people have read this book: "Grow as a ...

How to use VUE to call Ali Iconfont library online

Preface Many years ago, I was a newbie on the ser...

How to store text and pictures in MySQL

Large Text Data Types in Oracle Clob long text ty...

JavaScript implements click toggle function

This article example shares the specific code of ...

Three principles of efficient navigation design that web designers must know

Designing navigation for a website is like laying...

Solution to secure-file-priv problem when exporting MySQL data

ERROR 1290 (HY000) : The MySQL server is running ...

Detailed example of jQuery's chain programming style

The implementation principle of chain programming...

How to build svn server in linux

1: Install SVN yum install -y subversion 2. Creat...

Implementation of Node connection to MySQL query transaction processing

Table of contents Enter the topic mysql add, dele...

jQuery canvas generates a poster with a QR code

This article shares the specific code for using j...

Summarize the commonly used nth-child selectors

Preface In front-end programming, we often use th...

Detailed explanation of the difference between alt and title

These two attributes are often used, but their di...