jQuery .toggle event deprecated, What to use?

前端 未结 2 644
逝去的感伤
逝去的感伤 2020-12-11 17:46

Since the jQuery .toggle event method is deprecated. What are we suppose to use to simulate this event (alternate clicks)?

2条回答
  •  轮回少年
    2020-12-11 18:45

    var i = 0;    
    $('button').click(function() { 
        if (i == 0){        
            $('div').css({background: 'red'}) 
            i++; 
        } else { 
            $('div').css({background: 'yellow'}) 
            i = 0; 
        }
    });
    

提交回复
热议问题