how can I make jquery mobile "pagebeforeshow" event fire every time, not just on refresh
I开发者_运维百科 have a jquery mobile page that uses the following code to hide a button when the page is accessed.
$('div:jqmData(role="page")').live('pagebeforeshow',function(){
$("#apply_btn").hide()
});
My problem is that the event only fires when the page is refreshed and not when arriving at the page from somewhere else in the site.
I have tried using the "pageshow" event and the "pageinit" event but it still only fires when the page is refreshed.
Just to remember that live method has been removed from jQuery 1.9. You should use from now on the on method:
$( '#yourPage' ).on( 'pagebeforeshow',function(event){
$("#uniqueButtonId").hide();
});
Have a look at http://jquerymobile.com/demos/1.1.0/docs/api/events.html
This is the syntax:
$( '#yourPage' ).live( 'pagebeforeshow',function(event){
$("#uniqueButtonId").hide();
});
Good Luck
Strangely enough the short version doesn't work for me:
$( '#yourPage' ).on( 'pagebeforeshow',function(event){
$('#uniqueButtonId').hide();
});
but I have to use:
$(document).on( 'pagebeforeshow' , '#yourPage' ,function(event){
$('#uniqueButtonId').hide();
});
try this..
$('div:jqmData(role="page")').live('pagebeforeshow',function(){
$("#apply_btn",context).hide()
});
精彩评论