JavaScript实现简单留言版

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				padding: 0;
				margin: 0;
			}
			.wp{
				border: 1px #1B1B1B solid;
				height: 600px;
				width: 500px;
				margin: 20px auto;
				position: relative;
				background: url(bg.jpg);
				background-size: 100% 100%;
				/*border-radius: 5%;*/
				
			}
			#window{
				width: 500px;
				height: 300px;
				border-bottom: 1px #B3D4FC solid;
				position: absolute;
				top: 0;
				left: 0;
				overflow: auto;
			}
			#txt{
				position: absolute;
				bottom: 40px;
				left: 0;
				height: 200px;
				border-top: 1px #0077AA solid;
				width: 100%;
				cursor: pointer;
				font-size: 20px;
				background: #888888;
				/*border-radius: 10%;*/
			}
			#btn{
				width: 80px;
				height: 40px;
				position: absolute;
				bottom: 0;
				right: 20px;
			}
			#window li{
				list-style-type: none;
				font-size: 20px;
				margin-top: 10px;
				border: 1px #444444 solid;
				color: #FFFFFF;
				height: 40px;
				line-height: 40px;
				
			}
			#window input{
				float: right;
				height: 40px;
				width: 80px;
			}
			input:hover{
				background: #F00000;
				color: #FFFFFF;
				border: 0;
			}
		</style>
	</head>
	<body>
		<div class="wp">
			<div id="window">
			<!--	<li>1</li>-->
			</div>
			<textarea id="txt" value="1"></textarea>
			<input type="button" id="btn" value="发送" />
		</div>
	</body>
	<script type="text/javascript">
		var txt1=document.getElementById("txt");
		var btn=document.getElementById("btn");
		
		btn.onclick=function(){
			var txt2=document.getElementById("txt").value;
			var txt=txt2.trim();
			if(txt!=''){
//			console.log(txt.value);
var win=document.getElementById("window");
//创建一个新的li
var gg=document.createElement('li');
//创建一个新的文本节点
var ggText=document.createTextNode(txt);
//将文本节点添加到li中
gg.appendChild(ggText);
//将li添加到win中,用来显示
   win.appendChild(gg);
// console.log(txt1.value);
   txt1.value='';
   var btn2=document.createElement('input');
   btn2.type='button';
   btn2.value='删除';
   gg.appendChild(btn2);
   btn2.onclick=function(){
   var cor=confirm('你确定删除吗?');
   if(cor){
     var en=this.parentNode;       
     console.log(en);
    en.parentNode.removeChild(en);
   }
   }
   }else{
			alert('输入不能为空!');
   }
		}
	</script>
</html>

逻辑很简单,我也是个菜鸡,所有大佬手下留情

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值