简体   繁体   English

使用JQM和addClass更改按钮颜色每页仅工作一次

[英]Changing button colors with JQM and addClass only works once per page

I'm trying to change the background of a button for a mobile app. 我正在尝试更改移动应用程序按钮的背景。 The Click event seems too slow, so I used vmousedown. Click事件似乎太慢,因此我使用了vmousedown。 This works but only once per page. 这有效,但每页仅一次。 I'm doing this. 我在做

Mousedown
$(.headerNavBar).on('vmousedown','.logout',function() {
$(this).removeClass('ui-bar-c').addClass('ui-bar-c');
});
Mouse UP
$(.headerNavBar).on('vmouseup','.logout',function() {
$(this).removeClass('ui-bar-c');
});
$(.headerNavBar).on('tap','.logout',function() {
$(this).removeClass('ui-bar-c');
});

HTML is HTML是

<li><a href="#" class="logout" data-icon="back" data-theme="b">Log out</a></li>

The button is in a JQueryMobile page content block. 该按钮位于JQueryMobile页面内容块中。

If there is a better way to just change the background gradient that would be fine too. 如果有更好的方法来更改背景渐变,那也很好。

Update: I just noticed in the inspector that the class is being added and removed, it's just not updating on the page. 更新:我刚刚在检查器中注意到正在添加和删除该类,但是该类并未在页面上更新。

Use parent element or document to bind the event and give the selector. 使用父元素或文档来绑定事件并提供选择器。 Second thing you may check you have vmousedown it would be mousedown and same for vmouseup. 第二件事,您可能会检查是否具有vmousedown,这将是mousedown和vmouseup相同。

Mousedown 按下鼠标

$(document).on('vmousedown','.logout', function() {
   $(this).removeClass('ui-bar-c').addClass('ui-bar-c');
});

Mouse UP 鼠标向上

$(document).on('vmouseup','.logout', function() {
      $(this).removeClass('ui-bar-c');
});
$('body').delegate('.logout','vmousedown', function() {
   $(this).removeClass('ui-bar-c').addClass('ui-bar-c');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM