Blogger Information
Blog 3
fans 0
comment 0
visits 916
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
在线智能客服
皮卡丘
Original
280 people have browsed it

<!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>todoList:留言板</title>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
div{
width: 62.5rem;
height: auto;
margin: 0 auto;
margin-top: 50px;
}

input{
border: 1px solid salmon;
height: 2rem;
width: 20rem;
outline: none;

}
input[type=text]::placeholder {
color: blue;
padding-left:1rem;
}

.list li{
margin-top: 1rem;
list-style-type:none
}

.list li > button{

border-radius:0.5rem;
width:2.5rem;
height: 2rem;
outline: none;
margin-left: 1rem;
background-color: bisque;
border: none;

}



</style>
</head>
<body>
<div>
<input type="text" onkeydown="insertComment(this)" placeholder="请输入留言" autofocus>
<ul class="list">

</ul>
</div>
<script>
let patt = /[\u4E00-\u9FA5]/;

const insertComment = ((ele)=>{
if(event.key === ‘Enter’){
if(ele.value.length === 0){
alert(‘留言不能为空’);
ele.focus();

//直接返回
return false;
}
if(!ele.value.match(patt)){

alert(‘必须是汉字’);
ele.focus();

//直接返回
ele.value = null;
return false;

}


const ul = document.querySelector(‘.list’);
ele.value +=<button onclick="del(this.parentNode)">删除</button>
ul.insertAdjacentHTML(‘afterbegin’,<li>${ele.value}</li>)




ele.value = null;
}
})

const del = function(ele){
return confirm(‘是否删除’)?(ele.outerHTML = null) :false;
}
</script>
</body>
</html>

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post