我一直在努力了解jQuery keypress,keydown,keyup和input事件.但我发现它们很混乱.有人可以指出确切的区别吗?此外,我想知道当用户粘贴一段文本时,所有这些都会被触发. 谢谢 根据 jQuery docs:
谢谢 根据 jQuery docs:
The keypress event is sent to an element when the browser registers keyboard input. This is similar to the keydown event, except that modifier and non-printing keys such as Shift, Esc, and delete trigger keydown events but not keypress events. Other differences between the two events may arise depending on platform and browser.
The keyup event is sent to an element when the user releases a key on the keyboard.
The oninput event it’s an event that triggers whenever the input changes.
但是,在9以下的IE版本中不支持输入事件.在这种情况下,您可以使用专有事件onpropertychange,它与oninput相同.
但在您的情况下,您可以一起使用粘贴和更改事件.您也应该使用更改,因为粘贴仅发生在显式粘贴上支持它的浏览器上.