<script type="text/javascript">
	function checkTextArea(obj,maxWords){		
		var limit = maxWords;	
		var limittip = document.getElementById('limittip');
		var str = obj.value;	
		var len = str.length;
		var reallen = 0;
		for(i=0;i<len;i++){
			if(str.charCodeAt(i)>255){
				reallen += 2;
				if(reallen > limit){
					reallen -= 2; 
					obj.value = str.substr(0,i); 
					break;
					}
				}
				else{
					reallen++;
					if(reallen > limit){
						reallen--;
						obj.value = str.substr(0,i);
						break;
					}
				}
		}
		limittip.innerHTML = limit - reallen;	
	}
</script>

原文参考地址:http://www.decimage.com/web/js-for-textarea-count-bytes.html
查看全文
  相关解决方案