简体   繁体   中英

How to re-enable backspace key in Javascript

I am using keypress event to disable backspace key when <body contenteditable="true"> for selected text. After selecting text the backspace key is disabled properly. But, de-selecting text backspace key remain disabled. How do I re-enable backspace key in JavaScript?

CODE:

document.getElementById("cke_bdy").addEventListener("keypress", function(e) {
    var code = e.keyCode || e.which;
    if (code === 46 || code === 8) {
        flag = false;
        e.preventDefault();
        return false;
    }
}, false);

Attach an onblur event to the textarea with the inverse of the code used to disable the backspace key.

If the backspace key is disabled by searching for the key's ID and calling preventDefault(), remove the listener within the onblur event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM