js是unicode的,
所以你数据库最好也按unicode来考虑

解决方案 »

  1.   

    输入时要实时控制好象是不行, 但可以在失去焦点或提交时判断, 即调用函数来判断了。chr(a)<0即为汉字。
      

  2.   

    <script language=javascript>
    function checkLength(textbox)
    {
    var max = 8;//设置最大字节数
    var t = 0;
    var s = "";
    for(i=0;i<textbox.value.length;i++)
    {
    if(parseInt(textbox.value.charCodeAt(i))>256)
    {
    t += 2;
    if(t<=max)
    s += textbox.value.substr(i,1);
    }
    else
    {
    if(t<=max-1)
    s += textbox.value.substr(i,1);
    t++;
    }
    }
    if(t>max)
    {
    textbox.value = s;
    }
    }
    </script>
    <input type="text" onkeyup="return checkLength(this)" onpaste="checkLength(this)">变向的方法,你试一下能不能用。
    我想了好久才想出来这么做啊。
      

  3.   

    刚从梅花大哥那里学来的。<script language=javascript>
    function String.prototype.lenB(){return this.replace(/[^\x00-\xff]/g,"**").length;}
    </script>
    <input type=text onkeypress="if(this.value.lenB()>7)return false;">