如何保持按钮活动后按jQuery [英] How to keep button active after press with jQuery
本文介绍了如何保持按钮活动后按jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看过一些非常相似的问题,但没有找到我想要的答案。我已经确定了一个解决方法,但想知道正确的方式来执行任务。
I've seen some very similar questions floating around but haven't been able to find the answer I'm looking for. I've already determined a work-around but would like to know the proper way to perform the task.
我想要的是点击按钮,并具有活动状态保持持久。下一个单击将切换状态,这是所需的。我真正需要知道的是如何解决uiButton:活动状态。
What I desire is to click the button and have the active state stay persistent. The next click will toggle the state and that is desired. What I really need to know is how to address the uiButton:active state.
HTML:
<input type='button' class='uiButton' id='testbutton' value='testValue'>
CSS:
.uiButton{
background-color: red;
}
.uiButton:active{
background-color:blue;
}
Javascript / jQuery:
Javascript/jQuery:
$('.uiButton').click(function() {
$(this).toggleClass(//active state);
});
推荐答案
您应该创建一个活动类
CSS
CSS
.uiButton:active, .active {
background-color:blue;
}
JS / p>
JS
$('.uiButton').click(function() {
$(this).toggleClass("active");
});
这篇关于如何保持按钮活动后按jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文