<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document
</title>
</head>
<style>
textarea {
resize: none;
}
ul {
margin: 0;
padding: 0;
margin-top: 10px;
}
li {
list-style: none;
width: 282px;
}
li a {
float: right;
}
</style>
<body>
<textarea name="" id="" cols="30" rows="10"></textarea>
<button>提交
</button>
<ul></ul>
<script>
var text = document.querySelector('textarea');
var btn = document.querySelector('button');
var ul = document.querySelector('ul');
btn.onclick = function () {
if (text.value != "") {
var li = document.createElement("li");
li.innerHTML = text.value + "<a href='javascript:;'>删除</a>";
ul.insertBefore(li, ul.children[0]);
ul.children[0].children[0].onclick = function () {
ul.removeChild(this.parentNode);
}
}
}
</script>
</body>
</html>
转载请注明原文地址:https://tech.qufami.com/read-5622.html