Posted on 2007-10-23 09:46
草 鞋 阅读(534)
评论(0) 编辑 收藏 所属分类:
JavaScript
<script language=JavaScript>
function strlength(str){
var l=str.length; var n=l;
for (var i=0;i<l;i++){if (str.charCodeAt(i)<0||str.charCodeAt(i)>255) n++;}
return n;
}
function changebyte(value,length){
var l=strlength(value);
if (l<=length) {if (document.all!=null) document.all("byte").innerText="还可以输入"+(length-l)+"字节";}
else{document.all("byte").innerText="输入字节数超出范围";}
return true;
}
function changebyte1(value,length){
var l=strlength(value);
if (l<=length) {if (document.all!=null) document.all("byte1").innerText="还可以输入"+(length-l)+"字节";}
else{document.all("byte1").innerText="输入字节数超出范围";}
return true;
}
function changebyte2(value,length){
var l=strlength(value);
if (l<=length) {if (document.all!=null) document.all("byte2").innerText="还可以输入"+(length-l)+"字节";}
else{document.all("byte2").innerText="输入字节数超出范围";}
return true;
}
</script>
<form method="post" name=test onSubmit="return checkdata()" action="">
<TEXTAREA onkeydown="return changebyte1(document.test.icqcontent.value,20)" onkeyup="return changebyte1(document.test.icqcontent.value,20)" name=icqcontent cols=40 rows="3"></TEXTAREA>
<SPAN id=byte1><SCRIPT language=JavaScript>changebyte1(document.test.icqcontent.value,20);</SCRIPT></SPAN>
</form>