仿微博发布
##上代码
// An highlighted block
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
#box{
width: 280px;
/*height: 260px;*/
margin: 100px auto;
border: 1px solid #ccc;
padding: 10px;
}
textarea{
width: 240px;
vertical-align: bottom;
}
ul{
width: 240px;
list-style: none;
}
ul li{
border-bottom: 1px dashed #665533;
}
ul li a{
float: right;
text-decoration: none;
}
</style>
<script>
window.onload=function(){
var box=document.getElementById("box");
var txt=document.getElementById("txt");
var btn=document.getElementsByTagName("button")[0];
var ul=document.createElement("ul");
box.appendChild(ul);
btn.onclick=function(){
var lis=document.createElement("li");
// ul.appendChild(lis);
if(ul.children.length==0){
ul.appendChild(lis);
}else{
ul.insertBefore(lis,ul.children[0]);
}
lis.innerHTML=txt.value+"<a href ='javascript:;'>删除</a>";
txt.value="";
var as=document.getElementsByTagName("a");
for(var i=0;i<as.length;i++){
as[i].onclick=function(){
this.parentNode.style.display="none";
}
}
}
}
</script>
</head>
<body>
<div id="box">
<textarea name="" id="txt" cols="30" rows="10"></textarea>
<button>提交</button>
</div>
</body>
</html>