The following simple example using the model with js control the number of characters in textarea;

======
Example 1
======
<!DOCTYPE html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>test</title>
		<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
		<script type="text/javascript">
			function textcontrol(taId,maxSize) {
				// 默认 最大字符限制数
				var defaultMaxSize = 200;
				var ta = document.getElementById(taId);
				// 检验 textarea 是否存在
				if(!ta) {
					return;
				}
				// 检验 最大字符限制数 是否合法
				if(!maxSize) {
					maxSize = defaultMaxSize;
				} else {
					maxSize = parseInt(maxSize);
					if(!maxSize || maxSize < 1) {
						maxSize = defaultMaxSize;
					}
				}
				   if (ta.value.length > maxSize) {
					ta.value=ta.value.substring(0,maxSize);
					alert("超过最大字符限制:"+maxSize);
				} 
			}
		</script>
	</head>
	<body>
		<textarea name="ta1" cols="50" rows="10" onkeyup="textcontrol(this.id)"></textarea>
		<textarea name="ta2" cols="50" rows="10" onkeyup="textcontrol(this.id,5)"></textarea>
	</body>
</html>



Usage:
js the textcontrol (taId, maxSize) method to accept two parameters:
* The first parameter that needs textarea check the id, the parameters can not be empty;
* The second parameter is the maximum number of characters limit is optional, if no such parameter, or this parameter is not lawful, 600

Note:
This sample can not be detected on the right-paste, the following examples may be;

======
Example 2
======
<!DOCTYPE html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>test</title>
		<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
		<script type="text/javascript">
			// onchange 事件时(等同于 失去焦点),提示并限制字符数
			function taCheckOnChange(taId,maxSize) {
				// 默认 最大字符限制数
				var defaultMaxSize = getDefaultMaxSize();
				var ta = document.getElementById(taId);
				// 检验 textarea 是否存在
				if(!ta) {
					return;
				}
				// 检验 最大字符限制数 是否合法
				if(!maxSize) {
					maxSize = defaultMaxSize;
				} else {
					maxSize = parseInt(maxSize);
					if(!maxSize || maxSize < 1) {
						maxSize = defaultMaxSize;
					}
				}
				// 提示当前输入字符数
				var taTipDiv = document.getElementById("taTipDiv");
				taTipDiv.innerHTML=("当前字符数:" + ta.value.length + ",字数限制:" + maxSize);
			   if (ta.value.length > maxSize) {
					alert("当前字数 "+ta.value.length+" ,超过最大字符限制数 "+maxSize+" ,点击 \"确定\" 将自动截断。");
					ta.value=ta.value.substring(0,maxSize);
					taTipDiv.innerHTML=("当前字数:" + ta.value.length + ",字数限制:" + maxSize);
				} 
			}
			// 当键盘输入时,提示并限制字符数
			function taCheckOnKeyUp(taId,maxSize) {
				// 默认 最大字符限制数
				var defaultMaxSize = getDefaultMaxSize();
				var ta = document.getElementById(taId);
				// 检验 textarea 是否存在
				if(!ta) {
					return;
				}
				// 检验 最大字符限制数 是否合法
				if(!maxSize) {
					maxSize = defaultMaxSize;
				} else {
					maxSize = parseInt(maxSize);
					if(!maxSize || maxSize < 1) {
						maxSize = defaultMaxSize;
					}
				}	
				// 检验 最大字符限制数 是否合法
				if (ta.value.length > maxSize) {
					ta.value=ta.value.substring(0,maxSize);
				} 
				// 提示当前输入字符数
				var taTipDiv = document.getElementById("taTipDiv");			
                                taTipDiv.innerHTML=("当前字数:" + ta.value.length + ",字数限制:" + maxSize);
			}
			// 获得 默认 最大字符限制数
			function getDefaultMaxSize() {
				return 200;
			}
		</script>
	</head>
	<body>
		<div></div>
		<textarea name="ta1" cols="50" rows="10" onkeyup="taCheckOnKeyUp(this.id,20)" onchange="taCheckOnChange(this.id,20)" ></textarea>
	</body>
</html>




Usage:
There are two methods:
* TaCheckOnKeyUp (taId, maxSize) in onkeyup event trigger, suggesting that the current number of characters entered, and to limit the input, this method can restrict keyboard input, for right-paste is not valid;
* TaCheckOnChange (taId, maxSize) in the onchange event trigger (equivalent to the loss of focus), suggesting that the current number of characters entered, automatically cut off the extra characters, this method is mainly directed against right-paste detection;

Note:
This example used two methods to determine js, js call this method two parameters should also be shared the same (such as parameter maxSize);

======

======