在功能中启用ctrl + c和ctrl + v按钮

时间:2013-11-28 10:27:59

标签: javascript

我想在函数中添加代码以启用 ctrl + c ctrl + v ,数字已启用且字母表已禁用。此功能在文本框中使用,其中 ctrl + c ctrl + v 将被启用但不是字母表。我尝试了各种各样的东西,但无法通过它。有什么帮助我在代码中修改什么来启用它们?

function item_checkInput(object, e, len, nr) {
    var keycode, date, retval, value, newvalue, sel;
    if (window.event) {
        keycode = window.event.keyCode;
        range = window.event.RangeOffset;
    }
    else if (e.which != 0) {
        keycode = e.which;
        range = e.rangeOffset;
    }
    else {
        keycode = e.keyCode;
        range = e.rangeOffset;
    }
    date = new Date();
    value = object.value.replace(/\./g, "");
    if ( (keycode >= 48 && keycode <= 57) && e.rangeOffset != undefined )
        newvalue = value.substr(0,e.target.selectionStart) + String.fromCharCode(keycode) + value.substr(e.target.selectionEnd);
    else if ( (keycode >= 48 && keycode <= 57) && document.selection )
    {
        document.selection.createRange().text = String.fromCharCode(keycode);
        newvalue = object.value;
        object.value = value;
    }
    else
        newvalue = value;

    if (!NotallNumbers(e)) {
        return false;
    }
    if ( (keycode == 9) ) //tab (9)
    {
        if (newvalue.length == 13 && newvalue.substr(0, 7) == "10000") {
            newvalue = newvalue.substr(7);
        }
        if (newvalue.length == 6) {
            retval = check_itemnr(newvalue, nr);
            if (retval == false) {
                object.value = newvalue;
                focusEnSelect(object, true);
            }
            object.value = newvalue;
        }
        return false;
    }
    else if ( (keycode == 8) || (keycode == 46) || (keycode >= 35 && keycode <= 40) )

        return true;
    else if ( (keycode >= 48 && keycode <= 57) && ((date.getTime() - itemnr_keypress) > interval_scan) ) {

        if (newvalue.length == 13 && newvalue.substr(0,7) == "10000")
            newvalue = newvalue.substr(7);
        if ( (newvalue.length == len) ) {
            retval = artnr_checknr_art(newvalue, nr);
            if (retval == false) {
                   object.value = newvalue;
                   focusEnSelect(object, true);
            } else {
                object.value = newvalue;
                return false;
            }
            return retval;
        }
        itemnr_keypress = date.getTime();
        return true;
    }
    else if ( (keycode >= 48 && keycode <= 57) && (newvalue.length == 6) && (newvalue != "10000") ) {

        itemnr_keypress = date.getTime();

        retval = check_itemnr(newvalue, nr);
        if (retval == false) {
            object.value = newvalue;
            focusEnSelect(object, true);
        }
        return retval;
    }
    else if ( (keycode >= 48 && keycode <= 57) && (newvalue.length == 13) ) {

        itemnr_keypress = date.getTime();
        if (value.substr(0, 7) == "10000") {


            object.value = newvalue.substr(7);
            retval = check_itemnr(newvalue.substr(7), nr);
            if (retval == false) {
                focusEnSelect(object, true);
            }
            return false;
        }
        else {

            object.value = "";
            return false;
        }
        return true;
    }
    else if (keycode >= 48 && keycode <= 57) {
        itemnr_keypress = date.getTime();
        return true;
    }
    else if (keycode == 106) {
        retval = check_itemnr(newvalue, nr);
        if (retval == false) {
               object.value = newvalue;
               focusEnSelect(object, true);
        }
        return false;
    } else if (keycode == 13) {
        if (newvalue.length == 13 && newvalue.substr(0, 7) == "10000") {
            newvalue = newvalue.substr(7);
        }
        if (newvalue.length == 6) {
            retval = check_itemnr(newvalue, nr);
            if (retval == false) {
                object.value = newvalue;
                focusEnSelect(object, true);
            }
            object.value = newvalue;
        }
        return false;
    } else if (newvalue.length > 13) {
        return false;
    }

    return false;
}

0 个答案:

没有答案