简易click事件判断取代toggle

$( ".btn" ).on( "click" , function (){
     //通过判断按钮btn有没有active这个class名判断是否已经点击过
     if ($( this ).hasClass( "active" )){
     //如果有了active,假设已经点击过了
     //执行你的代码
     //把active去掉
     $( this ).removeClass( "active" );
     } else {
     //没有active,假设还没有点击过
     //执行你的代码
     $( this ).addClass( "active" );
     }
})

猜你喜欢

转载自blog.csdn.net/alanzhuhaihua/article/details/46863383