<!--StartFragment--><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META NAME="Author" CONTENT="Seagle.K">
<SCRIPT LANGUAGE="JavaScript">
function limitTxtByte(o, len)
{
var str = o.value;
var rscn = /^[\u4E00-\u9FA5]$/i;
var ach;
var rsstr = '';
var count = 0;
for (var i=0; i<str.length; i++)
{
ach = str.substr(i, 1);
if (rscn.test(ach))
{
if (count+2 <= len)
{
count += 2;
}else
{
break;
}
}else
{
if (count+1 <= len)
{
count += 1;
}else
{
break;
}
}
rsstr += ach;
}
if (rsstr != str)
{
o.value = rsstr;
}
}
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE="text" name="txt" onpropertychange="limitTxtByte(this, 4)">
</BODY>
</HTML>
posted on 2006-01-18 11:50
萌芽的叶子 阅读(342)
评论(0) 编辑 收藏 引用 所属分类:
html