控制TEXTAREA輸入框的最大字數
<SCRIPT LANGUAGE="JavaScript">
<!--
var maxLen=420;
function checkMaxInput(obj){
var m=obj.value.length;
var n=m;
var j=0;
for (var i=0;i<m;i++){
if (obj.value.charCodeAt(i)<0||obj.value.charCodeAt(i)>161){
n=n+1;
if ( i < 420 ){
j=j+1;
}
}
}
if(n>=maxLen){
obj.value=obj.value.substring(0,maxLen-j);
remLen1.innerText='[最大可输入';
remLen2.innerText=maxLen/2;
remLen3.innerText='汉字,';
remLen4.innerText='您已达到输入上限!';
remLen5.innerText=']';
}else{
remLen1.innerText='[最大可输入';
remLen2.innerText=maxLen/2;
remLen3.innerText='汉字,還可输入';
remLen4.innerText=(maxLen-n)/2;
remLen5.innerText='汉字]';
}
}
//-->
</SCRIPT>
<textarea name="MsgContent" cols="45" rows="5" onKeyDown="checkMaxInput(this)" onKeyUp="checkMaxInput(this)" onBlur="checkMaxInput(this)" style="width:600px; height:300px; border:1px solid #7e9db9;"><TRS:Column name="MsgContent" cutsize=100000></TRS:Column></textarea>
<font id="remLen1"></font>
<font color=red id="remLen2"></font>
<font id="remLen3"></font>
<font color=red id="remLen4"></font>
<font id="remLen5"></font>
<!--
var maxLen=420;
function checkMaxInput(obj){
var m=obj.value.length;
var n=m;
var j=0;
for (var i=0;i<m;i++){
if (obj.value.charCodeAt(i)<0||obj.value.charCodeAt(i)>161){
n=n+1;
if ( i < 420 ){
j=j+1;
}
}
}
if(n>=maxLen){
obj.value=obj.value.substring(0,maxLen-j);
remLen1.innerText='[最大可输入';
remLen2.innerText=maxLen/2;
remLen3.innerText='汉字,';
remLen4.innerText='您已达到输入上限!';
remLen5.innerText=']';
}else{
remLen1.innerText='[最大可输入';
remLen2.innerText=maxLen/2;
remLen3.innerText='汉字,還可输入';
remLen4.innerText=(maxLen-n)/2;
remLen5.innerText='汉字]';
}
}
//-->
</SCRIPT>
<textarea name="MsgContent" cols="45" rows="5" onKeyDown="checkMaxInput(this)" onKeyUp="checkMaxInput(this)" onBlur="checkMaxInput(this)" style="width:600px; height:300px; border:1px solid #7e9db9;"><TRS:Column name="MsgContent" cutsize=100000></TRS:Column></textarea>
<font id="remLen1"></font>
<font color=red id="remLen2"></font>
<font id="remLen3"></font>
<font color=red id="remLen4"></font>
<font id="remLen5"></font>