日期:2014-05-16  浏览次数:20364 次

jquery 控制freetextbox控件的长度
控制 freetextbox 长度的jquery该如何写哇 
ASP 里边写了个
<FTB:FreeTextBox ID="FreeTextBox1" runat="server" Width="550px"></FTB:FreeTextBox>
要如何才能用jquery把他的utf-8格式长度限制在4000个以内并且还能显示还能动态剩下多少个字啊?


------解决方案--------------------
JScript code
function b() {
            var txtbody = $(window.frames['FreeTextBox1_designEditor'].document).find('body').html();
            var bytelen = 0;
            var i;
            for (i = 0; i < txtbody.length; i++) {
                charCode = txtbody.charCodeAt(i);
                if (charCode < 0x007f) {
                    bytelen += 1;
                } else if ((0x0080 <= charCode) && (charCode <= 0x07ff)) {
                    bytelen += 2;
                } else if ((0x0800 <= charCode) && (charCode <= 0xffff)) {
                    bytelen += 3;
                }
            }
            alert(bytelen);
        }