在移动设备上切换活动课程

toggling active class on mobile

本文关键字:活动课 移动      更新时间:2023-09-26

我有一个按钮组,我正在切换活动类。只有一个按钮可以激活类

toggleActive: function(e) {
            var format;
            e.preventDefault();
            $(e.currentTarget).parent().siblings().children().removeClass("active");  
            $(e.currentTarget).addClass("active");

它在桌面上工作得很好,但在移动设备上,当用户可以同时使用两个手指和点击两个按钮时,它们都在同时获得类活动。我怎样才能解决这个问题?

if ( $('.buttonGroup').hasClass("active") ) {
     $('.buttonGroup').removeClass("active"); 
     $(this).addClass("active");
});