注:本文内容摘录自《Learning jQuery (4th Edition)》。
To react to ser behavior, we need to register our handlers using these event methods. Note that many DOM events only apply to certain element types; these subtleties are not covered here.
Binding
Binding
Event method |
Description |
.ready(handler) |
Binds handler to be called when the DOM and CSS are fully loaded. |
.on(type, [selector], [data], handler) |
Binds handler to be called when the given type of event is sent to the element. If selector is provided, performs event delegation. |
.off(type, [selector], [handler]) |
Removes bindings on the element. |
.bind(type, [data], handler) |
Binds handler to be called when the given type of event is sent to he element. In general, use .on() instead. |
.one(type, [data], handler) |
Binds handler to be called when the given type of event is sent to the element. Removes the binding when the handler is called. |
.unbind([type], [handler]) |
Removes the bindings on the element (for an event type, a particular handler, or all bindings). |
.delegate(selector, type, [data], handler) |
Binds handler to be called when the given type of event is sent to a descendant element matching selector. |
.delegate(selector, handlers) |
Binds a collection of handlers to be called when the given types of events are sent to a descendant element matching selector. |
.undelegate(selector, type, [handler]) |
Removes the bindings on the element previously bound with .delegate(). |
Shorthand binding
Shorthand binding
Event method |
Description |
.blur(handler) |
Binds handler to be called when the element loses keyboard forcus. |
.change(handler) |
Binds handler to be called when the element’s value changes. |
.click(handler) |
Binds handler to be called when the element is clicked. |
.dblclick(handler) |
Binds handler to be called when the element is double-clicked. |
.error(handler) |
Binds handler to be called when the element receives an error event (browser-dependent). |
.focus(handler) |
Binds handler to be called when the element gains keyboard focus. |
.focusin(handler) |
Binds handler to be called when the element, or a descendant, gains keyboard focus. |
.focusout(handler) |
Binds handler to be called when the element, or a descendant, loses keyboard focus. |
.keydown(handler) |
Binds handler to be called when a key is pressed and the element has keyboard forcus. |
.keypress(handler) |
Binds handler to be called when a keystroke occurs and the element has keyboard focus. |
.keyup(handler) |
Binds handler to be called when a key is released and the element has keyboard focus. |
.load(handler) |
Binds handler to be called when the element finishes leading. |
.mousedown(handler) |
Binds handler to be called when the mouse button is pressed within the element. |
.mouseenter(handler) |
Binds handler to be called when the mouse pointer enters the element. Not affected by event bubbling. |
.mouseleave(handler) |
Binds handler to be called when the mouse pointer leaves the element. Not affected by event bubbling. |
.mousemove(handler) |
Binds handler to be called when the mouse pointer moves within the element. |
.mouseout(handler) |
Binds handler to be called when the mouse pointer leaves the element. |
.mouseover(handler) |
Binds handler to be called when the mouse pointer enters the element. |
.mouseup(handler) |
Binds handler to be called when the mouse button is released within the element. |
.resize(handler) |
Binds handler to be called when the element is resized. |
.scroll(handler) |
Binds handler to be called when the element;s scroll position changes. |
.select(handler) |
Binds handler to be called when text in the elemet is selected. |
.submit(handler) |
Binds handler to be called when the form element is submitted. |
.unload(handler) |
Binds handler to be called when the element is unloaded from memory. |
.hover(enter, leave) |
Binds enter to be called when the mouse enters the element, and leave to be when the mouse leaves it. |
Triggering
Triggering
Event method |
Description |
.trigger(type, [data]) |
Triggers handlers for the vent on the element and executes the default action for the event. |
.triggerHandler(type, [data]) |
Triggers handlers for the event on the element without executing any default actions. |
Shorthand triggering
Shorthand triggering
Event method |
Description |
.blur() |
Triggers the blur event. |
.change() |
Triggers the change event. |
.click() |
Triggers the click event. |
.dblclick() |
Triggers the dblclick event. |
.error() |
Triggers the error event. |
.focus() |
Triggers the focus event. |
.keydown() |
Triggers the keydown event. |
.keypress() |
Triggers the keypress event. |
.keyup() |
Triggers the keyup event. |
.select() |
Triggers the select event. |
.submit() |
Triggers the submit event. |
Utility
Utility
Event method |
Description |
$.proxy(fn, context) |
Creates a new function that executes with the given context. |
最新评论
大哥资深网民啊,01年我还在念小学。。
看着有点难过。。。
嘿嘿,谢谢老哥,也祝老哥事业蒸蒸日上。
我是你唯一的药学类友情链接网站。 作为一个80后的过来人祝福你,生活越来越好。
这篇文章,我们中学那会老师课堂上念给我们听的。
哈哈哈哈哈,没想到啊, 我有手抄版
嗯,是的
好心办坏事多了去啦
哈哈,是的,我15年末来上海写代码了,一晃三年多过去了,好快。
今天看QQ好友的时候突然看到了你的名字,想起几年前在药品国际注册群挺活跃/厉害的你,现在不见踪影了。就搜了一下,没想到你现在转行去写代码了... (刚才打漏了一句话...)