jQuery移动按钮保持按下状态
我有一个连接到ajax POST的jQuery移动按钮.如果POST失败,则jQuery移动按钮将保持按下状态,而不是弹出".有什么想法吗?
I have a jQuery mobile button hooked up to an ajax POST. If the POST fails, the jQuery mobile button stays pressed instead of ``popping up". Any ideas?
可以轻松完成.
这里有一个 jsFiddle
示例,用于我以前的回答之一: http://jsfiddle.net /3PhKZ/7/
如果您看一看,下面是这行代码:
If you take a look there's this line of code:
$.mobile.activePage.find('.ui-btn-active').removeClass('ui-btn-active ui-focus');
它将尝试在当前活动页面上找到按下的按钮,如果成功,它将删除2个负责按钮按下状态的类.不幸的是,这里纯CSS解决方案是不可能的.您可以测试此示例,只需在顶部注释一下,然后看看会发生什么.
It will try to find pressed button on a current active page, if it succeed it will remove 2 classes responsible for a button pressed state. Unfortunately pure CSS solution is impossible here. You can test this example, just comment top line and see what will happen.
最后一个选择器$ .mobile.activePage仅可在pagebeforeshow,pageshow,pagebeforechange,pagechange,pagebeforehide和pagehide页面事件期间使用,因此将其考虑在内.
One last thing selector $.mobile.activePage can only be used during the pagebeforeshow, pageshow, pagebeforechange, pagechange, pagebeforehide and pagehide page event so takes this into account.
如果您不能使用此选择器,只需将其替换为页面ID,如下所示:
In case you cant use this selector just replace it with a page id, like this:
$('#pageID').find('.ui-btn-active').removeClass('ui-btn-active ui-focus');
所以您的最终代码将如下所示:
So your final code would look like this:
$.ajax( "example.php" )
.success(function() { doStuff(); })
.error(function() {
$('#pageID').find('.ui-btn-active').removeClass('ui-btn-active ui-focus');
})