效果图:
 
 
 
  
 
 html代码:
 
  
 
  
 
 <!doctype html>
<html>
<script>
function check(obj,id01,id02,maxLength){
	
	var textarea = document.getElementById('Context');
	
	if(textarea.value.length > maxLength){
		
		alert("Input can not beyond 10  character !!!");
		textarea.value = textarea.value.substring(0,maxLength);
		
		}
	else{
		
		id01.value = textarea.value.length;
		id02.value = maxLength-id01.value;
			
		}
	}
    
</script>
	<head>
		<title>限制文本框中的输入字数</title>
	</head>
	<body>
		<form name="myForm" method="post">
			标题:<input type="text" name="textTitle" size="30" maxlength="8">(限输入8个文字)<br>
			内容:<textarea rows="10" cols="30" id="Context"name="Context" onKeyDown="check(this,textCount,textCount2,10)" onKeyUp="check(this,textCount,textCount2,10)"   oncut="return false;"οnpaste="return false;"></textarea><br>
			(限输入10个文字)<br>
			您已经输入了<input type="text" id="textCount" size="3" readonly>个字<br>
            还能继续输入<input type="text" id="textCount2" size="3" readonly>个字
		</form>
	</body>
</html>
  
  
                
        
    
                    转载请注明原文地址: https://ju.6miu.com/read-675721.html