How can I “undo” the programmatic insertion of text into a textarea?

后端 未结 12 655
失恋的感觉
失恋的感觉 2020-12-17 09:27

I have a textarea and a button. Clicking the button causes text to be inserted into the textarea.

Is there a way to allow a user to press Ctrl/Cmd+z to undo the inse

12条回答
  •  春和景丽
    2020-12-17 10:04

    $("#target").keypress(function(event) {
      if ( event.which == 'Z' && first press == 'Cmd' && second press == 'Ctrl') {//check for key press
         event.preventDefault();
        text.value = defaultValueForTextField
       }
    });
    

    That should be what you are looking for. First and Second press will need to be saved as you want combo presses. You will indeed need to save a default text value though.

提交回复
热议问题