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

Detailed explanation of the loop form item example in Vue

Sometimes we may encounter such a requirement, th...

Basic learning tutorial of table tag in HTML

Table label composition The table in HTML is comp...

JavaScript to achieve fireworks effects (object-oriented)

This article shares the specific code for JavaScr...

Two simple ways to remove text watermarks from web pages

<br /> When we browse certain websites and s...

mysql5.7 installation and configuration tutorial under Centos7.3

This article shares the MySQL 5.7 installation an...

Comprehensive understanding of line-height and vertical-align

Previous words Line-height, font-size, and vertica...

Convert psd cut image to div+css format

PSD to div css web page cutting example Step 1: F...

How to reset the root password in Linux mysql-5.6

1. Check whether the MySQL service is started. If...

Detailed explanation of error handling examples in MySQL stored procedures

This article uses an example to describe the erro...

Linux general java program startup script code example

Although the frequency of starting the shell is v...

HTML thead tag definition and usage detailed introduction

Copy code The code is as follows: <thead> &...

How to implement navigation function in WeChat Mini Program

1. Rendering2. Operation steps 1. Apply for Tence...

Steps to build a Docker image using Dockerfile

Dockerfile is a text file that contains instructi...

Detailed tutorial on installing MySQL offline on CentOS7

1. Delete the original mariadb, otherwise mysql c...