留言板

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
			window.onload=function(){
				var oText=document.getElementById("text1");
				var oUl=document.getElementById("ul1");
				
				oText.onkeyup=function(ev){
					
					var ev=ev||event;
//					alert(this.value)
					if(this.value!=""){
//						ctrl+回车 就可以发送
						if(ev.keyCode==13 && ev.ctrlKey){
							var oLi=document.createElement("li");
							oLi.innerHTML=this.value;
							
							if(oUl.children[0]){
								oUl.insertBefore(oLi,oUl.children[0]);
							}else{
								oUl.appendChild(oLi);
							}
						}
					}
				}
			}
		</script>
	</head>
	<body>
		<input type="text" id="text1" />
		<ul id="ul1"></ul>
	</body>
</html>

 

posted @ 2018-11-28 16:32  webxy  阅读(128)  评论(0编辑  收藏  举报