现在,toggle(...)
在 jQuery 1.8 中被弃用,然后在 jQuery 1.9 中被删除。
除了使用jQuery migrate脚本之外,在一般情况下可以使用什么代替toggle(fn, fn2);
具有相同的功能?
相关问题(针对特定情况提出):除了toggle,还能用什么?
我知道,toggle()
的功能并没有被删除,只是无法添加自定义的toggle函数(除了默认的显示/隐藏功能)。
现在,toggle(...)
在 jQuery 1.8 中被弃用,然后在 jQuery 1.9 中被删除。
除了使用jQuery migrate脚本之外,在一般情况下可以使用什么代替toggle(fn, fn2);
具有相同的功能?
相关问题(针对特定情况提出):除了toggle,还能用什么?
我知道,toggle()
的功能并没有被删除,只是无法添加自定义的toggle函数(除了默认的显示/隐藏功能)。
这里是一个简单的实现:
$.fn.toggleClick = function() {
var methods = arguments; // Store the passed arguments for future reference
var count = methods.length; // Cache the number of methods
// Use return this to maintain jQuery chainability
// For each element you bind to
return this.each(function(i, item){
// Create a local counter for that element
var index = 0;
// Bind a click handler to that element
$(item).on('click', function() {
// That when called will apply the 'index'th method to that element
// the index % count means that we constrain our iterator between 0
// and (count-1)
return methods[index++ % count].apply(this, arguments);
});
});
};
并将其用作
$('selector').toggleClick( function1, function2, ... );
return this
以保持链接。 - Gabriele Petriolireturn
? - Naftalireturn false
,我们希望将其传递给我们自己的单击处理程序以供使用。 - Gabriele Petriolitoggle('slow', function(){...})
一样? - Ares Draguna