博客列表 >在线智能客服

在线智能客服

皮卡丘
皮卡丘原创
2022年11月09日 16:32:38270浏览

<!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>

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议