how can I make jquery mobile “pagebeforeshow” event fire every time, not just on refresh

心已入冬 提交于 2019-12-20 01:01:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!