Home > Web Front-end > JS Tutorial > body text

Detailed examples of jQuery.die() function usage

巴扎黑
Release: 2017-06-30 14:00:03
Original
1402 people have browsed it

The

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

The die() function is mainly used to unblock the event processing function bound by the live() function.

This function belongs to the jQuery object (instance).

Syntax

This function was added in jQuery 1.3. It was marked as obsolete starting from jQuery 1.7 and was removed in jQuery 1.9. It mainly has the following two forms of usage:

Usage 1: jQuery 1.4.1 newly supports not specifying any parameters.

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

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

Usage 2: jQuery 1.4.3 newly supports this usage.

jQueryObject.die(eventsMap)

Variation of usage one, used to remove multiple event handlers of multiple event types at the same time. eventsMap is an object, each attribute is applied to the parameter events in method 1, and the value is applied to the parameter handler in method 1.

Parameters

Parameter Description

events Optional/String type One or more event types separated by spaces and optional namespace, For example "click", "focus click", "keydown.myPlugin".

handler Optional/event handling function specified by Function type.

eventsMap Object class is a type Object object, each of its attributes corresponds to the event type and optional namespace (parameter events), and the attribute value corresponds to the bound Event handling function (parameter handler).

namespace Namespace specified by String type, such as ".foo", ".myPlugin".

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

The selector of the current jQuery object that calls the die() function must be consistent with the selector of the jQuery object that calls the live() function.

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

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

In fact, the parameters of the die() 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 die () function to unbind the event, the corresponding code is as follows:

In addition, the die() function can also remove only the event binding of the specified namespace.

The above is the detailed content of Detailed examples of jQuery.die() function usage. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!