jQuery callbacks函数

callbacks函数方法:
callbacks.add() 将回调或回调的集合添加到回调列表
callbacks.disable() 禁用回调列表做任何事情。
callbacks.disabled() 确定回调列表是否已禁用。
callbacks.empty() 从列表中删除所有回调。
callbacks.fire() 使用给定的参数调用所有回调。
callbacks.fired() 确定回调是否已经被调用至少一次。
callbacks.fireWith() 使用给定的上下文和参数调用列表中的所有回调。
callbacks.has() 确定列表是否附加了任何回调。 如果回调作为参数提供,则确定它是否在列表中。
callbacks.lock() 将回调列表锁定在当前状态。
callbacks.locked() 确定回调列表是否已被锁定。
callbacks.remove() 从回调列表中删除回调或回调的集合。

callbacks.lock()示例:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>callbacks.lock demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<div id="log"></div>

<script>
// Simple function for logging results
var log = function( value ) {
  $( "#log" ).append( "<p>" + value + "</p>" );
};

// Two sample functions to be added to a callbacks list
var foo = function( value ) {
  log( "foo: " + value );
};
var bar = function( value ) {
  log( "bar: " + value );
};

// Create the callbacks object with the "memory" flag
var callbacks = $.Callbacks( "memory" );

// Add the foo logging function to the callback list
callbacks.add( foo );

// Fire the items on the list, passing an argument
callbacks.fire( "hello" );
// Outputs "foo: hello"

// Lock the callbacks list
callbacks.lock();

// Try firing the items again
callbacks.fire( "world" );
// As the list was locked, no items were called,
// so "foo: world" isn't logged

// Add the foo function to the callback list again
callbacks.add( foo );

// Try firing the items again
callbacks.fire( "silentArgument" );
// Outputs "foo: hello" because the argument value was stored in memory

// Add the bar function to the callback list
callbacks.add( bar );

callbacks.fire( "youHadMeAtHello" );
// Outputs "bar: hello" because the list is still locked,
// and the argument value is still stored in memory
</script>

</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

生活中的思索

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值