Home > Web Front-end > JS Tutorial > Detailed explanation of the usage and precautions of jQuery.unbind() function

Detailed explanation of the usage and precautions of jQuery.unbind() function

巴扎黑
Release: 2017-06-25 15:13:41
Original
2151 people have browsed it

The

unbind() function is used to remove the event handling function of one or more events bound to the matching element.

The unbind() function is mainly used to unbind the event processing function bound by the bind() function.

This function belongs to the jQuery object (instance).

Syntax

The unbind() function mainly has the following two forms of usage:

Usage 1:

jQueryObject.unbind( [ events [, handler ]] )

Remove the event handler function handler bound to the events event of the current matching element.

Usage 2:

jQueryObject.unbind( eventObject )

is the Event object passed in by the specified event processing function, used to remove the corresponding event processing function.

Parameters

Parameter Description

events Optional/String Type One or more event types separated by spaces and optional Namespace , such as "click", "focus click", "keydown.myPlugin".

handler Optional/event handling function specified by Function type.

eventObject Object class is an Event object, used to remove the event processing function passed in to the object.

jQuery 1.4.3 newly supports the parameter handler which can be false. The event handler function is used to remove the bound event when the handler parameter is false.

If the parameter handler is omitted, all event handlers bound to events of the specified type matching the element will be removed.

If all parameters are omitted, it means to remove any event handlers on the matching element for any event type bound to any element.

Return value

unbind()The return value of the function is of jQuery type and returns the current jQuery object itself.

In fact, the parameters of the unbind() function are all filtering conditions, and only event processing functions that match all parameter conditions will be removed. The more parameters there are, the more qualifications there are and the smaller the range that is removed.

Example & Description

Please refer to the following initial HTML code:

<input id="btn1" type="button" value="点击1" />
<input id="btn2" type="button" value="点击2" />
<a id="a1" href="#">CodePlayer</a>
Copy after login

First, we bind events to the above button and elements, and then use unbind () function unbinds events. The corresponding code is as follows:

unbind() function can also remove functions based on the incoming event object. The following jQuery code only allows the prompt box to pop up when the button [Click 1] is clicked for the first time, and then removes the click event immediately.

The above is the detailed content of Detailed explanation of the usage and precautions of jQuery.unbind() function. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template