1、文本框长度限制:
<body >
<textarea onkeypress="return test(this,2)"></textarea>
<script language="javascript">
function test(obj,maxlen){ //maxlen为限定的最大长度,超过此长度时写不进文本框
if(obj.value.length>maxlen-1){
return false;
}
}
</script>
</body>
2、单个中文字符的脚本显示:
<input type="text" value="aaas测试s" onfocus="testchinese(this)">
<script language="javascript">
function testchinese(obj){
var ss = new String(obj.value);
alert(ss.length+" "+ss+" "+String.fromCharCode(ss.charCodeAt(4)));
}
</script>