这是我的切换按钮,我想如果按钮有.active类别做其他事情。
<button type="button" class="btn btn-lg btn-toggle" data-toggle="button" ></button>
答案 0 :(得分:0)
快乐编码:)
$('.btn-toggle').click(function() {
if($(this).hasClass('btn-active')){
alert('button has activat class so perform task 1');
// write your task 1
// ...
} else {
alert('button has not activat class so perform task 2');
// write your task 2
// ...
}
$(this).toggleClass('btn-active');
});
.btn-toggle {
background-color : red;
}
.btn-active {
background-color : blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" class="btn btn-lg btn-toggle">Button</button>