javascript 限定输入字数

   <script type="text/javascript">

      function checkMaxlengths(obj, evt, maxLength) {
        var event = window.event || evt;
        if (event.keyCode != 8) {
            if (obj.value.length > maxLength) {
                obj.value = obj.value.substring(0, maxLength);
                evt.returnValue = false;
            }
        }
        var lbl = document.getElementById("<%=labSep.ClientID%>");
        lbl.innerHTML = maxLength - (obj.value.length);
    }       

        </script>

onkeyup="checkMaxlengths(this,event,120)"

<asp:Label ID="labSep" runat="server" Text="120"></asp:Label>
posted on 2009-08-21 15:04  prayforsmile  阅读(187)  评论(0编辑  收藏  举报