What event is fired when cutting or pasting text (or ctrl + z'd) into a text field?

I use keyup to detect when the content in the text area changes, but somehow Facebook can detect the Ctrl + X event in the text box right after pressing the "X" key. What will be this event?

+4
source share
3 answers

Most modern browsers support cut , copy and paste events. Try the following to prove it to yourself:

 <textarea oncut="alert('Cut!')" rows="3" cols="40"></textarea> 
+3
source

I would suggest that they create a binding to keydown and set some kind of state variable when the control key is pressed, and then when they receive the keyup event, they check the state variable and act accordingly.

0
source

Hehehe I understood it myself!

In the keypress event for the text field:

 window.setTimeout((function(self) { return function() { console.log(self.value); } })(this), 0); 

This will give the current value of the text field, not the value until the key is pressed. I have only tested this on Firefox 4 so far.

Now my startup text box is as good as Facebook!

0
source

Source: https://habr.com/ru/post/1332634/


All Articles