Jquery mobile 导航栏按钮保持按下状态
我用两个Jquery mobile 导航栏按钮保持按下状态,jquery-mobile,user-interface,navbar,Jquery Mobile,User Interface,Navbar,我用两个 <li><a href="#" type="button" > text</a></li> 在我的应用程序的页脚导航栏中键入按钮,以触发我的应用程序中的函数(不用于导航)。每次按下按钮后,按钮保持按下状态,直到按下导航栏中的另一个按钮。如何避免这种行为?从上次按下的按钮手动删除classui btn active $('#button_id').removeClass('ui-btn-active'); 编辑 最好的方法是重新定
<li><a href="#" type="button" > text</a></li>
在我的应用程序的页脚导航栏中键入按钮,以触发我的应用程序中的函数(不用于导航)。每次按下按钮后,按钮保持按下状态,直到按下导航栏中的另一个按钮。如何避免这种行为?从上次按下的按钮手动删除class
ui btn active
$('#button_id').removeClass('ui-btn-active');
编辑
最好的方法是重新定义classui btn active
的样式,与“unclicked”按钮的样式相同。例如:
.ui-footer .ui-navbar .ui-btn-active {
border: 1px solid #222;
background: #333333;
font-weight: bold;
color: #fff;
text-shadow: 0 -1px 1px #000;
background-image: -webkit-gradient(linear, left top, left bottom, from( #555), to( #333));
background-image: -webkit-linear-gradient(#555, #333);
background-image: -moz-linear-gradient(#555, #333);
background-image: -ms-linear-gradient(#555, #333);
background-image: -o-linear-gradient(#555, #333);
background-image: linear-gradient(#555, #333);
}
示例。另一种处理方法是从事件绑定返回false,这样JQM就不会首先添加类。
Test
<button type="button" class="btn btn-default touchbtn">Test</button>
$('.touchbtn').bind('touchstart', function() {
$(this).css('background-color', 'black');
});
$('.touchbtn').bind('touchend', function() {
$(this).css('background-color', 'white');
});
$('.touchbtn').bind('touchtstart',function(){
$(this.css('background-color','black');
});
$('.touchbtn').bind('touchend',function(){
$(this.css('background-color','white');
});
好的,我明白了。问题似乎是,ui btn active
类是在click事件之后添加的。您可以稍后尝试使用一个小的超时来删除,但我知道这不是最好的方法。我一直在寻找更好的答案…好吧,忘记手动删除类。最好的方法是重新定义它的样式。我将编辑答案。