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

Detailed explanation of jQuery.unload() function

巴扎黑
Release: 2017-06-29 10:40:13
Original
1959 people have browsed it

The unload() function is used to bind a handler function to the unload event of each matching element. In addition, you can also pass some additional data to the event handling function.

The unload event will be triggered when the page exits. This event is mainly used for window object, , elements.

In addition, you can call this function multiple times for the same element to bind multiple event handlers. When the unload event is triggered, jQuery will execute the bound event processing functions in the order of binding.

The unload event varies greatly between different browsers and different versions. It is very likely that it will not be able to correctly execute the corresponding event processing function, so it is not recommended to use this event. Please do your own browser compatibility testing before use, or use the beforeunload event instead.

To delete an event bound via unload(), use the unbind() function.

This function belongs to the jQuery object (instance).

Syntax

This function was added in jQuery 1.0, but has been marked as obsolete starting from 1.8.

jQueryObject.unload( [ data ,] handler )

Parameter

Parameter Description

data Optional/any type When triggering an event, you need to pass event .data Arbitrary data passed to the event handler function.

The event processing function specified by the handler Function type.

jQuery 1.4.3 new support: unload() supports data parameter.

This in the parameter handler points to the current DOM element. unload() will also pass in a parameter to the handler: the Event object representing the current event.

Return value

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

Example & Description

Now, we bind a handler function to the unload event of the window object (you can bind multiple ones, and they will be executed in sequence in the binding order when triggered):

$(window).unload( function(){
    alert("离开当前文档!");
} );
Copy after login

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

Related labels:
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!