我正在尝试使按钮按下效果,点击按钮在JqueryMobile中。我可以使用css添加类来获得这种效果,点击按钮,但是它不会恢复以前的状态(在发布时)。
下面是我的index.html代码:
<div class="loginbutton" id="sgninBtn"> </div>下面是我的脚本代码,以获得按钮效果:
$(document).on("click", "#sgninBtn", function() {
$("#sgninBtn").addClass('loginbuttonclick');
});
$(document).on("taphold", "#sgninBtn", function() {
$("#sgninBtn").addClass('loginbuttonpressed');
}); 下面是我的css代码,以获得按钮效果:
.loginbutton {width:300px; height:48px; background:url(../images/samplespriteimage-login.png) 0 0px;}
.loginbuttonpressed {width:300px; height:48px; background:url(../images/samplespriteimage-login.png) 0 -48px;}
.loginbuttonclick {width:300px; height:48px; background:url(../images/samplespriteimage-login.png) 0 -96px;} 所有这些类都会根据需要应用,但是一旦它单击并得到了特定的样式,它就不会在按钮发布时恢复到以前的样式。在JqueryMobile中是否有任何关于发布的事件使它成为work.Or有任何方法来解决这个问题。
在event.But之前,我正在删除页面上添加的类,理想情况下,我希望它在按钮发布时发生。请在this.Thanks上帮我
发布于 2013-09-25 10:59:14
您所需要的只是在事件完成后进行.removeClass()。
click事件可分为两个事件:
mousedown、vmousedown或touchstart的开始。在这里,你可以添加类或者做其他的事情。
$('#sgninBtn').on('vmousedown touchstart',函数(e) { if (e.type == 'touchstart') { $(this).addClass('loginbuttonpressed');}{ $(this).addClass('loginbuttonclick');}返回false;};mouseup,vmouseup或touchend。在这里,您删除类或做其他事情。
$('#sgninBtn').on('vmouseup touchend',函数(e) { if (e.type == 'touchend') { $(this).removeClass('loginbuttonpressed');}{ $(this).removeClass('loginbuttonclick');}返回false;};。
https://stackoverflow.com/questions/18999393
复制相似问题