我是 java 脚本的新手。我对按键和更改事件有点困惑。
示例代码如下
$("input").live('change',function ()
{
Alert("Change event call");
});
/
$("input").live('keypress',function ()
{
Alert("Keypress event call");
});
Keypress事件到底是什么时候调用和change事件调用的?
最佳答案
改变事件
The
change
event is sent to an element when its value changes. This event is limited to<input>
elements,<textarea>
boxes and<select>
elements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.
按键事件
The
keypress
event is sent to an element when the browser registers keyboard input. This is similar to thekeydown
event, except in the case of key repeats. If the user presses and holds a key, akeydown
event is triggered once, but separatekeypress
events are triggered for each inserted character. In addition, modifier keys (such as Shift) triggerkeydown
events but notkeypress
events.A
keypress
event handler can be attached to any element, but the event is only sent to the element that has the focus. Focusable elements can vary between browsers, but form elements can always get focus so are reasonable candidates for this event type.
引用资料:
关于javascript - JavaScript 中的 keypress 和 change 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13525958/