Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use jQuery.Callbacks ()

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use jQuery.Callbacks (), has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

JQuery.Callbacks (flags)

Description: a multi-purpose callback list object that provides a powerful way to manage callback function lists.

Added version: 1.7jQuery.Callbacks (flags)

Flags

Type: String

An optional list of flags separated by space tags to change the behavior in the callback list.

The $.ajax () and $.Deferred () basic functional components of jQuery are provided inside $. Callable (). It can be used as a function of a new component similar to the basic definition.

Methods supported by $. Callers (), including callbacks.add (), callbacks.remove (), callbacks.fire () and callbacks.disable ().

Getting started (getting started)

Here are two sample methods named fn1 and fn2:

Function fn1 (value) {

Console.log (value)

}

Function fn2 (value) {

Fn1 ("fn2 says:" + value)

Return false

}

These can be added as callback functions as a list of $.Callbacks and called as follows:

Var callbacks = $.Callrooms ()

Callbacks.add (fn1)

/ / outputs: foo!

Callbacks.fire ("foo!")

Callbacks.add (fn2)

/ / outputs: bar!, fn2 says: bar!

Callbacks.fire ("bar!")

As a result, it makes it easy to construct a complex list of callbacks, and the input values can be easily used as needed by as many functions as possible.

The above two specific methods: .add () and .fire () .add () support adding new callback lists, while .fire () provides a way to handle callback methods in the same list.

The other method, by .remove () of $.Callbacks, removes a specific callback from the callback list. Here is an example of the use of .remove ():

Var callbacks = $.Callrooms ()

Callbacks.add (fn1)

/ / outputs: foo!

Callbacks.fire ("foo!")

Callbacks.add (fn2)

/ / outputs: bar!, fn2 says: bar!

Callbacks.fire ("bar!")

Callbacks.remove (fn2)

/ / only outputs foobar, as fn2 has been removed.

Callbacks.fire ("foobar")

Supported Flags (supported Flags)

This flags parameter is an optional parameter for $. Callbacks () and is structured as an optional list of flags separated by space tags to change the behavior in the callback list (for example. $.Callflower ('unique stopOnFalse')).

Thank you for reading this article carefully. I hope the article "how to use jQuery.Callbacks ()" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 261

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report