小白的自学自记。发布留言超低配,我自己都不好意思发了。
<!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>
</head>
<style>
.announce input {
height: 300px;
}
.text {
height: 100px;
}
ul li {
display: block;
width: 100px;
background-color: pink;
}
</style>
<body>
<div class="announce">
<textarea class="text">
</textarea><button>发布</button>
</div>
<div>
<ul>
</ul>
</div>
<script>
var text1 = document.querySelector('.text');
var button1 = document.querySelector('button');
var ul1 = document.querySelector('ul');
button1.onclick = function() {
if (text1.value == '') {
alert('请输入内容');
console.log('1');
} else {
var li1 = document.createElement('li')
var a = document.create
li1.innerHTML = text1.value;
// ul1.appendChild(li1);
ul1.insertBefore(li1, ul1.children[0])
text1.value = ''
}
}
</script>
</body>
</html>