<!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>Document</title>
<style>
.box {
font-size: 0;
}
input,
button {
outline: none;
font-size: 10px;
}
input {
width: 100px;
height: 14px;
border: 1px solid red;
vertical-align: bottom;
}
button {
background-color: steelblue;
color: white;
border: 0;
}
ul {
width: 200px;
height: 300px;
list-style: none;
}
li {
margin-left: -20px;
width: 200px;
height: 30px;
border-bottom: 1px solid steelblue;
}
</style>
</head>
<body>
<div class="box">
<input type="text">
<button>发布</button>
</div>
<ul>
<!-- <li>111</li> -->
</ul>
<script>
const input = document.querySelector('input')
const btn = document.querySelector('button')
const ul = document.querySelector('ul')
input.addEventListener('foucs',function(){
})
btn.addEventListener('click',function() {
const i = input.value.trim()
if(i) {
const li = document.createElement("li")
li.innerHTML = i
ul.insertBefore(li,ul.children[0])
}
input.value = ''
})
</script>
</body>
</html>