实现文本域的maxlength

//onPropertyChange
function chkMaxLen(obj, e) {
            var maxLen = 200;
            if (getRangeById()) {
                return true;
            }
            if (obj.value.length >= maxLen) {
                if (e.keyCode == 46 || e.keyCode == 8 || (e.keyCode >= 33 && e.keyCode <= 40)) {
                    return true;
                } else {
                    if (!e.ctrlKey)
                        e.returnValue = "";
                    return false;
                }
            }
        }
        function getRangeById() {
            var o = document.selection.createRange();
            if (o.text.length > 0) {
                return true;
            } else {
                return false;
            }
        }
        function clearSelect() {
            var o = document.selection.createRange();
            o.text = "";
        }
              


onpaste="return false;"                            
oncopy="return false;" oncut="return false;" onfocus="clearSelect();" onKeydown="chkMaxLen(this,event)"
 onblur="chkMaxLen(this,event)"




你可能感兴趣的:(function)