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.

">
立诚勿怠,格物致知
It's all about connecting the dots

Event methods in jQuery

注:本文内容摘录自《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.
赞(0) 打赏
文章名称:《Event methods in jQuery》
文章链接:https://www.orzzone.com/event-methods-in-jquery.html
商业联系:yakima.public@gmail.com

本站大部分文章为原创或编译而来,对于本站版权文章,未经许可不得用于商业目的,非商业性转载请以链接形式标注原文出处。
本站内容仅供个人学习交流,不做为任何投资、建议的参考依据,因此产生的问题需自行承担。

评论 抢沙发

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力提供更多优质内容!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册