Home  >  Article  >  Web Front-end  >  Detailed explanation of jQuery.unload() function

Detailed explanation of jQuery.unload() function

巴扎黑
巴扎黑Original
2017-06-29 10:40:131926browse

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, 6c04bd5ca3fcae76e30b72ad730ca86d, f900b4fc197b16ab214eecf015bb6bd2 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("离开当前文档!");
} );

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!

Statement:
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