当输入文字内容后,文本就显示在方框中;当输入为空时,提示“请输入一点文字 ”。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>无标题文档</title>
	<style type="text/css">
		#box1{
			width:300px;
			height:400px;
			border:1px solid #999;
		}
		#text1{
			width:180px;
		}
	</style>
	<script type="text/javascript">
		window.onload=function (){
			var oBox=document.getElementById("box1");
			var oText=document.getElementById("text1");
			var oSpan=document.getElementById("span1");
			var oButton=document.getElementById("button1");
			oButton.onclick=function (){
				if (oText.value==""){
						alert("请输入一点文字");
					}
				else {
					oBox.innerHTML=oBox.innerHTML+oSpan.innerHTML+oText.value+"<br />";//这里的书写顺序要注意。
					oText.value="";
				}
			}
		}
	</script>
</head>
<body>
	<div id="box1"></div><br />
	<span id="span1">一点点:</span><input id="text1" type="text"  value=""/>
	<input id="button1" type="button" value="提交" />
</body>
</html>
原文:http://www.cnblogs.com/yddwang/p/5604112.html