I've been using keyup to detect when content in a textarea changes, but somehow Facebook can detect a Ctrl+X event in a textbox immediately when the X is pressed down. What event would this be?
I've been using keyup to detect when content in a textarea changes, but somehow Facebook can detect a Ctrl+X event in a textbox immediately when the X is pressed down. What event would this be?
Share Improve this question edited Aug 6, 2021 at 4:36 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Dec 19, 2010 at 0:59 NickNick 5,44011 gold badges43 silver badges71 bronze badges 2-
Isn't that what
onchange
is for? – Gabe Commented Dec 19, 2010 at 1:12 - 2 I could be wrong, but I thought onchange was only when the element lost focus.. – Nick Commented Dec 19, 2010 at 2:01
3 Answers
Reset to default 4Most current browsers support cut
, copy
and paste
events. Try the following to prove this to yourself:
<textarea oncut="alert('Cut!')" rows="3" cols="40"></textarea>
I would guess they make a bind to the keydown, and set some sort of state variable when the control key is pressed, then when they receive a keyup event, they check the state variable and act accordingly.
Hehehe I figured it out on my own!
In the keypress event for the textarea:
window.setTimeout((function(self) {
return function() {
console.log(self.value);
}
})(this), 0);
This will give the current value of the textarea as opposed to the value before the key was pressed. I've only verified this on Firefox 4 so far though.
Now my autogrowing textbox is as nice as Facebook's!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745197840a4616178.html
评论列表(0条)