How can I disable all keyboard keys?

后端 未结 4 584
你的背包
你的背包 2021-01-12 09:14

I am searching for a possibility to disable all keyboard keys in a textarea. I found some examples on the web to disable some single ones but how can I disable the whole key

4条回答
  •  情话喂你
    2021-01-12 10:00

    Assuming you have in textare the reference of your textarea, maybe something like:

    textearea.onkeydown = textarea.onkeypress = function() { return false };
    

    That it's probably an overkill, but... Considering to use the attribute readonly instead:

    textarea.readOnly = true
    

    In the first case you're still able to copy/paste using the mouse, in the second case you can only copy (using keys or mouse doesn't matter).

提交回复
热议问题