01-查找父节点
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 查找父节点</ title>
< style>
.father {
width : 300px;
height : 300px;
background-color : red;
}
.son {
width : 100px;
height : 100px;
background-color : pink;
}
</ style>
</ head>
< body>
< div class = " father" >
< div class = " son" > 儿子</ div>
</ div>
< script>
let son = document. querySelector ( '.son' ) ;
son. addEventListener ( 'click' , function ( ) {
son. parentNode. style. display = 'none' ;
} )
</ script>
</ body>
</ html>
02-关闭二维码案例
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 关闭二维码案例</ title>
< style>
div {
position : relative;
left : 800px;
top : 100px;
width : 160px;
height : 160px;
}
div i {
position : absolute;
left : -15px;
top : -5px;
cursor : pointer;
}
</ style>
</ head>
< body>
< div>
< img src = " code.png" alt = " " >
< i class = " close_btn" > X</ i>
</ div>
< script>
let i = document. querySelector ( 'i' ) ;
i. addEventListener ( 'click' , function ( ) {
this . parentNode. style. display = 'none' ;
} )
</ script>
</ body>
</ html>
效果展示
03-关闭多个二维码案例
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 关闭多个二维码案例</ title>
< style>
.erweima {
width : 149px;
height : 152px;
border : 1px solid #000;
background : url(./images/456.png) no-repeat;
position : relative;
}
.close {
position : absolute;
right : -52px;
top : -1px;
width : 50px;
height : 50px;
background : url(./images/bgs.png) no-repeat -159px -102px;
cursor : pointer;
border : 1px solid #000;
}
</ style>
</ head>
< body>
< div class = " erweima" >
< span class = " close" > </ span>
</ div>
< div class = " erweima" >
< span class = " close" > </ span>
</ div>
< div class = " erweima" >
< span class = " close" > </ span>
</ div>
< div class = " erweima" >
< span class = " close" > </ span>
</ div>
< div class = " erweima" >
< span class = " close" > </ span>
</ div>
< script>
let sons = document. querySelectorAll ( '.close' ) ;
for ( let i = 0 ; i < sons. length; i++ ) {
sons[ i] . addEventListener ( 'click' , function ( ) {
this . parentNode. style. visibility = 'hidden' ;
} )
}
</ script>
</ body>
</ html>
效果展示
04-查找子节点
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 查找子节点</ title>
< style> </ style>
</ head>
< body>
< button> 点击</ button>
< ul>
< li> 我是孩子</ li>
< li> 我是孩子</ li>
< li> 我是孩子</ li>
< li> 我是孩子</ li>
< li> 我是孩子</ li>
< li> 我是孩子</ li>
</ ul>
< script>
let btn = document. querySelector ( 'button' ) ;
let ul = document. querySelector ( 'ul' ) ;
btn. addEventListener ( 'click' , function ( ) {
for ( let i = 0 ; i < ul. children. length; i++ ) {
ul. children[ i] . style. color = 'red' ;
}
ul. children[ 0 ] . style. color = 'green' ;
} )
</ script>
</ body>
</ html>
05-查找兄弟节点
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 查找兄弟节点</ title>
</ head>
< body>
< button> 点击</ button>
< ul>
< li> 第1个</ li>
< li class = " test" > 第2个</ li>
< li> 第3个</ li>
< li> 第4个</ li>
</ ul>
< script>
let btn = document. querySelector ( 'button' ) ;
let two = document. querySelector ( '.test' ) ;
btn. addEventListener ( 'click' , function ( ) {
two. nextElementSibling. style. color = 'green' ;
two. previousElementSibling. style. color = 'yellow' ;
} )
</ script>
</ body>
</ html>
06-追加节点
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 增加节点</ title>
</ head>
< body>
< ul>
< li> 我是大毛</ li>
< li class = " two" > 我是二毛</ li>
</ ul>
< script>
let li = document. createElement ( 'li' ) ;
li. innerHTML = '我是小明' ;
let ul = document. querySelector ( 'ul' ) ;
ul. insertBefore ( li, ul. children[ 1 ] ) ;
</ script>
</ body>
</ html>
07-克隆节点
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 克隆节点</ title>
</ head>
< body>
< ul>
< li> 我是内容</ li>
</ ul>
< script>
let ul = document. querySelector ( 'ul' ) ;
let newUL = ul. cloneNode ( true ) ;
document. body. appendChild ( newUL) ;
</ script>
</ body>
</ html>
08-删除节点
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 删除节点</ title>
</ head>
< body>
< button> 点击 </ button>
< ul>
< li> 我是内容</ li>
</ ul>
< script>
let btn = document. querySelector ( 'button' ) ;
let ul = document. querySelector ( 'ul' ) ;
btn. addEventListener ( 'click' , function ( ) {
ul. removeChild ( ul. children[ 0 ] ) ;
} )
</ script>
</ body>
</ html>
09-时间对象
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 时间对象</ title>
</ head>
< body>
< script>
let date = new Date ( '2022-12-2 18:50:10' ) ;
console. log ( date) ;
</ script>
</ body>
</ html>
10-时间对象常用方法
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 时间对象常用方法</ title>
</ head>
< body>
< script>
let date = new Date ( ) ;
console. log ( date. getFullYear ( ) ) ;
console. log ( date. getMonth ( ) + 1 ) ;
console. log ( date. getDate ( ) ) ;
console. log ( date. getHours ( ) ) ;
console. log ( date. getMinutes ( ) ) ;
console. log ( date. getSeconds ( ) ) ;
console. log ( date. getDay ( ) ) ;
</ script>
</ body>
</ html>
11-页面显示时间案例
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 页面显示时间案例</ title>
< style>
div {
width : 400px;
height : 50px;
background-color : pink;
text-align : center;
line-height : 50px;
}
</ style>
</ head>
< body>
< div> </ div>
< script>
let arr = [ '星期日' , '星期一' , '星期二' , '星期三' , '星期四' , '星期五' , '星期六' ] ;
let div = document. querySelector ( 'div' ) ;
getTime ( ) ;
setInterval ( getTime, 1000 ) ;
function getTime ( ) {
let date = new Date ( ) ;
let year = date. getFullYear ( ) ;
let month = date. getMonth ( ) + 1 ;
let date1 = date. getDate ( ) ;
let hour = date. getHours ( ) ;
let minute = date. getMinutes ( ) ;
let second = date. getSeconds ( ) ;
let day = date. getDay ( ) ;
div. innerHTML = '今天是:' + year + '年' + month + '月' + date1 + '日' + hour + ':' + minute + ':' + second + arr[ day] ;
}
</ script>
</ body>
</ html>
效果展示
12-时间戳
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 时间戳</ title>
</ head>
< body>
< script>
console. log ( + new Date ( ) ) ;
console. log ( + new Date ( '2022-3-3 12:00:00' ) ) ;
</ script>
</ body>
</ html>
13-下班倒计时案例
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> 下班倒计时案例</ title>
< style>
.countdown {
width : 240px;
height : 305px;
text-align : center;
line-height : 1;
color : #fff;
background-color : brown;
overflow : hidden;
}
.countdown .next {
font-size : 16px;
margin : 25px 0 14px;
}
.countdown .title {
font-size : 33px;
}
.countdown .tips {
margin-top : 80px;
font-size : 23px;
}
.countdown small {
font-size : 17px;
}
.countdown .clock {
width : 142px;
margin : 18px auto 0;
overflow : hidden;
}
.countdown .clock span,
.countdown .clock i {
display : block;
text-align : center;
line-height : 34px;
font-size : 23px;
float : left;
}
.countdown .clock span {
width : 34px;
height : 34px;
border-radius : 2px;
background-color : #303430;
}
.countdown .clock i {
width : 20px;
font-style : normal;
}
</ style>
</ head>
< body>
< div class = " countdown" >
< p class = " next" > 今天是2022年3月17日</ p>
< p class = " title" > 下班倒计时</ p>
< p class = " clock" >
< span id = " hour" > 00</ span>
< i> :</ i>
< span id = " minutes" > 25</ span>
< i> :</ i>
< span id = " scond" > 20</ span>
</ p>
< p class = " tips" >
现在是18:30:00
</ p>
</ div>
< script>
let hour = document. querySelector ( '#hour' ) ;
let minute = document. querySelector ( '#minutes' ) ;
let second = document. querySelector ( '#scond' ) ;
let p = document. querySelector ( '.tips' ) ;
time ( ) ;
setInterval ( time, 1000 )
function time ( ) {
let now = + new Date ( ) ;
let last = + new Date ( '2022-3-17 18:30:00' )
let count = ( last - now) / 1000 ;
let h = parseInt ( count / 60 / 60 % 24 ) ;
h = h < 10 ? '0' + h : h;
let m = parseInt ( count / 60 % 60 ) ;
m = m < 10 ? '0' + m : m;
let s = parseInt ( count % 60 ) ;
s = s < 10 ? '0' + s : s;
hour. innerHTML = h;
minute. innerHTML = m;
second. innerHTML = s;
let date = new Date ( ) ;
let hour1 = date. getHours ( ) ;
let minute1 = date. getMinutes ( ) ;
let second1 = date. getSeconds ( ) ;
p. innerHTML = '现在是' + hour1 + ':' + minute1 + ':' + second1;
}
</ script>
</ body>
</ html>
效果展示
14-学成在线案例重构
index.html
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< meta http-equiv = " X-UA-Compatible" content = " ie=edge" >
< title> 学车在线首页</ title>
< link rel = " stylesheet" href = " style.css" >
< style>
</ style>
</ head>
< body>
< div class = " box w" >
< div class = " box-hd" >
< h3> 精品推荐</ h3>
< a href = " #" > 查看全部</ a>
</ div>
< div class = " box-bd" >
< ul class = " clearfix" >
</ ul>
</ div>
</ div>
< script>
let data = [ {
src: 'images/course01.png' ,
title: 'Think PHP 5.0 博客系统实战项目演练' ,
num: 1125
} , {
src: 'images/course02.png' ,
title: 'Android 网络动态图片加载实战' ,
num: 357
} , {
src: 'images/course03.png' ,
title: 'Angular2 大前端商城实战项目演练' ,
num: 22250
} , {
src: 'images/course04.png' ,
title: 'Android APP 实战项目演练' ,
num: 389
} , {
src: 'images/course05.png' ,
title: 'UGUI 源码深度分析案例' ,
num: 124
} , {
src: 'images/course06.png' ,
title: 'Kami2首页界面切换效果实战演练' ,
num: 432
} , {
src: 'images/course07.png' ,
title: 'UNITY 从入门到精通实战案例' ,
num: 888
} , {
src: 'images/course08.png' ,
title: '我会变,你呢?' ,
num: 590
} , {
src: 'images/course08.png' ,
title: '我会变,你呢?' ,
num: 590
} ]
let ul = document. querySelector ( 'ul' ) ;
for ( let i = 0 ; i < data. length; i++ ) {
let li = document. createElement ( 'li' ) ;
li. innerHTML = ` <img src= ${ data[ i] . src} alt="">
<h4>
${ data[ i] . title}
</h4>
<div class="info">
<span>高级</span> • <span> ${ data[ i] . num} </span>人在学习
</div>`
console. log ( data. length) ;
ul. appendChild ( li) ;
}
</ script>
</ body>
</ html>
style.css
* {
margin : 0;
padding : 0;
}
.w {
width : 1200px;
margin : auto;
}
body {
background-color : #f3f5f7;
}
li {
list-style : none;
}
a {
text-decoration : none;
}
.clearfix:before,.clearfix:after {
content : "" ;
display : table;
}
.clearfix:after {
clear : both;
}
.clearfix {
*zoom : 1;
}
.header {
height : 42px;
margin : 30px auto;
}
.logo {
float : left;
width : 198px;
height : 42px;
}
.nav {
float : left;
margin-left : 60px;
}
.nav ul li {
float : left;
margin : 0 15px;
}
.nav ul li a {
display : block;
height : 42px;
padding : 0 10px;
line-height : 42px;
font-size : 18px;
color : #050505;
}
.nav ul li a:hover {
border-bottom : 2px solid #00a4ff;
color : #00a4ff;
}
.search {
float : left;
width : 412px;
height : 42px;
margin-left : 70px;
}
.search input {
float : left;
width : 345px;
height : 40px;
border : 1px solid #00a4ff;
border-right : 0;
color : #bfbfbf;
font-size : 14px;
padding-left : 15px;
}
.search button {
float : left;
width : 50px;
height : 42px;
border : 0;
background : url(images/btn.png) ;
}
.user {
float : right;
line-height : 42px;
margin-right : 30px;
font-size : 14px;
color : #666;
}
.banner {
height : 421px;
background-color : #1c036c;
}
.banner .w {
height : 421px;
background : url(images/banner2.png) no-repeat top center;
}
.subnav {
float : left;
width : 190px;
height : 421px;
background : rgba ( 0,0,0, 0.3) ;
}
.subnav ul li {
height : 45px;
line-height : 45px;
padding : 0 20px;
}
.subnav ul li a {
font-size : 14px;
color : #fff;
}
.subnav ul li a span {
float : right;
}
.subnav ul li a:hover {
color : #00a4ff;
}
.course {
float : right;
width : 230px;
height : 300px;
background-color : #fff;
margin-top : 50px;
}
.course h2 {
height : 48px;
background-color : #9bceea;
text-align : center;
line-height : 48px;
font-size : 18px;
color : #fff;
}
.bd {
padding : 0 20px;
}
.bd ul li {
padding : 14px 0;
border-bottom : 1px solid #ccc;
}
.bd ul li h4 {
font-size : 16px;
color : #4e4e4e;
}
.bd ul li p {
font-size : 12px;
color : #a5a5a5;
}
.bd .more {
display : block;
height : 38px;
border : 1px solid #00a4ff;
margin-top : 5px;
text-align : center;
line-height : 38px;
color : #00a4ff;
font-size : 16px;
font-weight : 700;
}
.goods {
height : 60px;
background-color : #fff;
margin-top : 10px;
box-shadow : 0 2px 3px 3px rgba ( 0,0,0, 0.1) ;
line-height : 60px;
}
.goods h3 {
float : left;
margin-left : 30px;
font-size : 16px;
color : #00a4ff;
}
.goods ul {
float : left;
margin-left : 30px;
}
.goods ul li {
float : left;
}
.goods ul li a {
padding : 0 30px;
font-size : 16px;
color : #050505;
border-left : 1px solid #ccc;
}
.mod {
float : right;
margin-right : 30px;
font-size : 14px;
color : #00a4ff;
}
.box {
margin-top : 30px;
}
.box-hd {
height : 45px;
}
.box-hd h3 {
float : left;
font-size : 20px;
color : #494949;
}
.box-hd a {
float : right;
font-size : 12px;
color : #a5a5a5;
margin-top : 10px;
margin-right : 30px;
}
.box-bd ul {
width : 1225px;
}
.box-bd ul li {
position : relative;
top : 0;
float : left;
width : 228px;
height : 270px;
background-color : #fff;
margin-right : 15px;
margin-bottom : 15px;
transition : all .3s;
}
.box-bd ul li:hover {
top : -8px;
box-shadow : 2px 2px 2px 2px rgba ( 0,0,0,.3) ;
}
.box-bd ul li img {
width : 100%;
}
.box-bd ul li h4 {
margin : 20px 20px 20px 25px;
font-size : 14px;
color : #050505;
font-weight : 400;
}
.box-bd .info {
margin : 0 20px 0 25px;
font-size : 12px;
color : #999;
}
.box-bd .info span {
color : #ff7c2d;
}
.footer {
height : 415px;
background-color : #fff;
}
.footer .w {
padding-top : 35px;
}
.copyright {
float : left;
}
.copyright p {
font-size : 12px;
color : #666;
margin : 20px 0 15px 0;
}
.copyright .app {
display : block;
width : 118px;
height : 33px;
border : 1px solid #00a4ff;
text-align : center;
line-height : 33px;
color : #00a4ff;
font-size : 16px;
}
.links {
float : right;
}
.links dl {
float : left;
margin-left : 100px;
}
.links dl dt {
font-size : 16px;
color : #333;
margin-bottom : 5px;
}
.links dl dd a {
color : #333;
font-size : 12px;
}
效果展示
15-微博发布案例
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" />
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" />
< meta http-equiv = " X-UA-Compatible" content = " ie=edge" />
< title> 微博发布</ title>
< style>
* {
margin : 0;
padding : 0;
}
ul {
list-style : none;
}
.w {
width : 900px;
margin : 0 auto;
}
.controls textarea {
width : 878px;
height : 100px;
resize : none;
border-radius : 10px;
outline : none;
padding-left : 20px;
padding-top : 10px;
font-size : 18px;
}
.controls {
overflow : hidden;
}
.controls div {
float : right;
}
.controls div span {
color : #666;
}
.controls div .useCount {
color : red;
}
.controls div button {
width : 100px;
outline : none;
border : none;
background : rgb ( 0, 132, 255) ;
height : 30px;
cursor : pointer;
color : #fff;
font : bold 14px '宋体' ;
transition : all 0.5s;
}
.controls div button:hover {
background : rgb ( 0, 225, 255) ;
}
.controls div button:disabled {
background : rgba ( 0, 225, 255, 0.5) ;
}
.contentList {
margin-top : 50px;
}
.contentList li {
padding : 20px 0;
border-bottom : 1px dashed #ccc;
position : relative;
}
.contentList li .info {
position : relative;
}
.contentList li .info span {
position : absolute;
top : 15px;
left : 100px;
font : bold 16px '宋体' ;
}
.contentList li .info p {
position : absolute;
top : 40px;
left : 100px;
color : #aaa;
font-size : 12px;
}
.contentList img {
width : 80px;
border-radius : 50%;
}
.contentList li .content {
padding-left : 100px;
color : #666;
word-break : break-all;
}
.contentList li .the_del {
position : absolute;
right : 0;
top : 0;
font-size : 28px;
cursor : pointer;
}
</ style>
</ head>
< body>
< div class = " w" >
< div class = " controls" >
< img src = " ./images/9.6/tip.png" alt = " " /> < br />
< textarea placeholder = " 说点什么吧..." id = " area" cols = " 30" rows = " 10" maxlength = " 200" > </ textarea>
< div>
< span class = " useCount" id = " useCount" > 0</ span>
< span> /</ span>
< span> 200</ span>
< button id = " send" > 发布</ button>
</ div>
</ div>
< div class = " contentList" >
< ul id = " list" > </ ul>
</ div>
</ div>
< li hidden >
< div class = " info" >
< img class = " userpic" src = " ./images/9.6/03.jpg" />
< span class = " username" > 死数据:百里守约</ span>
< p class = " send-time" > 死数据:发布于 2020年12月05日 00:07:54</ p>
</ div>
< div class = " content" > 死数据:111</ div>
< span class = " the_del" > X</ span>
</ li>
< script>
let dataArr = [ {
uname: '司马懿' ,
imgSrc: './images/9.5/01.jpg'
} , {
uname: '女娲' ,
imgSrc: './images/9.5/02.jpg'
} , {
uname: '百里守约' ,
imgSrc: './images/9.5/03.jpg'
} , {
uname: '亚瑟' ,
imgSrc: './images/9.5/04.jpg'
} , {
uname: '虞姬' ,
imgSrc: './images/9.5/05.jpg'
} , {
uname: '张良' ,
imgSrc: './images/9.5/06.jpg'
} , {
uname: '安其拉' ,
imgSrc: './images/9.5/07.jpg'
} , {
uname: '李白' ,
imgSrc: './images/9.5/08.jpg'
} , {
uname: '阿珂' ,
imgSrc: './images/9.5/09.jpg'
} , {
uname: '墨子' ,
imgSrc: './images/9.5/10.jpg'
} , {
uname: '鲁班' ,
imgSrc: './images/9.5/11.jpg'
} , {
uname: '嬴政' ,
imgSrc: './images/9.5/12.jpg'
} , {
uname: '孙膑' ,
imgSrc: './images/9.5/13.jpg'
} , {
uname: '周瑜' ,
imgSrc: './images/9.5/14.jpg'
} , {
uname: '老夫子' ,
imgSrc: './images/9.5/15.jpg'
} , {
uname: '狄仁杰' ,
imgSrc: './images/9.5/16.jpg'
} , {
uname: '扁鹊' ,
imgSrc: './images/9.5/17.jpg'
} , {
uname: '马可波罗' ,
imgSrc: './images/9.5/18.jpg'
} , {
uname: '露娜' ,
imgSrc: './images/9.5/19.jpg'
} , {
uname: '孙悟空' ,
imgSrc: './images/9.5/20.jpg'
} , {
uname: '黄忠' ,
imgSrc: './images/9.5/21.jpg'
} , {
uname: '百里玄策' ,
imgSrc: './images/9.5/22.jpg'
} , ]
let textarea = document. querySelector ( 'textarea' ) ;
let useCount = document. querySelector ( '.useCount' ) ;
let send = document. querySelector ( '#send' ) ;
let ul = document. querySelector ( 'ul' ) ;
textarea. addEventListener ( 'input' , function ( ) {
useCount. innerHTML = textarea. value. length;
} )
send. addEventListener ( 'click' , function ( ) {
if ( textarea. value. trim ( ) === '' ) {
textarea. value = '' ;
useCount. innerHTML = 0 ;
return alert ( '内容不能为空' ) ;
}
function getRandom ( min, max) {
return Math. floor ( Math. random ( ) * ( max - min + 1 ) ) + min
}
let random = getRandom ( 0 , dataArr. length - 1 )
let li = document. createElement ( 'li' )
li. innerHTML = ` <div class="info">
<img class="userpic" src= ${ dataArr[ random] . imgSrc} >
<span class="username"> ${ dataArr[ random] . uname} </span>
<p class="send-time"> ${ new Date ( ) . toLocaleString ( ) } </p>
</div>
<div class="content"> ${ textarea. value} </div>
<span class="the_del">X</span>`
let del = li. querySelector ( '.the_del' ) ;
del. addEventListener ( 'click' , function ( ) {
ul. removeChild ( li) ;
} )
ul. insertBefore ( li, ul. children[ 0 ] ) ;
textarea. value = '' ;
useCount. innerHTML = 0 ;
} )
</ script>
</ body>
</ html>
效果展示