问题
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.
回答1:
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
回答2:
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();
});
回答3:
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();
});
回答4:
try this..
$('div:jqmData(role="page")').live('pagebeforeshow',function(){
$("#apply_btn",context).hide()
});
来源:https://stackoverflow.com/questions/7549571/how-can-i-make-jquery-mobile-pagebeforeshow-event-fire-every-time-not-just-on