Javascript 我怎样才能让jquery mobile“pagebeforeshow”事件每次都触发,而不仅仅是刷新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7549571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 02:40:58  来源:igfitidea点击:

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

javascriptjqueryeventsjquery-mobile

提问by Finglish

I have a jquery mobile page that uses the following code to hide a button when the page is accessed.

我有一个 jquery 移动页面,它使用以下代码在访问页面时隐藏按钮。

$('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.

我曾尝试使用“pageshow”事件和“pageinit”事件,但它仍然只在页面刷新时触发。

回答by jalogar

Just to remember that live method has been removed from jQuery 1.9. You should use from now on the onmethod:

请记住,实时方法已从 jQuery 1.9 中删除。从现在开始,您应该使用on方法:

$( '#yourPage' ).on( 'pagebeforeshow',function(event){
    $("#uniqueButtonId").hide();
});

回答by TheGwa

Have a look at http://jquerymobile.com/demos/1.1.0/docs/api/events.html

看看http://jquerymobile.com/demos/1.1.0/docs/api/events.html

This is the syntax:

这是语法:

$( '#yourPage' ).live( 'pagebeforeshow',function(event){
    $("#uniqueButtonId").hide();
});

Good Luck

祝你好运

回答by quasi

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();
});

回答by user1049890

try this..

尝试这个..

$('div:jqmData(role="page")').live('pagebeforeshow',function(){
    $("#apply_btn",context).hide()
});