为了账号安全,请及时绑定邮箱和手机立即绑定

在jQuery> 1.8中使用什么而不是`toggle(...)`?

在jQuery> 1.8中使用什么而不是`toggle(...)`?

繁星coding 2019-09-03 20:08:45
现在已经在jQuery 1.8toggle(...)中弃用,然后在jQuery 1.9中删除一般可以使用什么(除了使用jQuery迁移脚本)而不是那些toggle(fn, fn2);具有相同类型的功能?相关问题(询问具体案例):使用什么而不是切换?我知道这toggle()功能是不删除,只是(来自显示/隐藏默认功能除外)添加自定义切换功能的能力。
查看完整描述

2 回答

?
元芳怎么了

TA贡献1798条经验 获得超7个赞

这是一个简单的实现:


$.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, ... );


查看完整回答
反对 回复 2019-09-03
?
三国纷争

TA贡献1804条经验 获得超7个赞

以便我们尊重用户对其传递方法的处理方式。例如,如果应用于链接,用户可能会return false在最后执行,我们希望将其传递给我们自己的单击处理程序以供使用。

查看完整回答
反对 回复 2019-09-03
  • 2 回答
  • 0 关注
  • 650 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信