Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何使用$.mobile.navigate在不同的闭包下发送参数到pagebeforeshow_Jquery_Jquery Mobile - Fatal编程技术网

Jquery 如何使用$.mobile.navigate在不同的闭包下发送参数到pagebeforeshow

Jquery 如何使用$.mobile.navigate在不同的闭包下发送参数到pagebeforeshow,jquery,jquery-mobile,Jquery,Jquery Mobile,嗨,在我的应用程序中,我使用下面的代码从一个div导航到另一个div $.mobile.navigate( "#formsEnterId", { info: "info about the #formsEnterIdhash" }); $("#formsEnterId").on('pagebeforeshow', function (event, data) { console.log("Entered page before show::",data); //H

嗨,在我的应用程序中,我使用下面的代码从一个div导航到另一个div

$.mobile.navigate( "#formsEnterId", { info: "info about the #formsEnterIdhash" });

$("#formsEnterId").on('pagebeforeshow', function (event, data) {
            console.log("Entered page before show::",data);    //How to fetch the info here??
        });
在pagebeforeshow事件中,我想获取info属性。我不知道如何获取 信息属性。但是页面导航成功

我还使用了$.mobile.changepage,但运气不好

请有人帮助我在pagebeforeShow事件中获取信息属性。 我已经在网上看到了相关的答案


但这并不能解决我的问题,因为我的页面导航脚本和pagebeforeshow事件处于不同的闭包下。

当所有内容都加载到DOM中时,我们可以创建一个全局对象来存储数据

实例:

另一种方法是将变量存储在本地存储器中

$(document).on('pagebeforeshow', '#index', function(){      
    $(document).on('click', '#change-page-button', function(){    
        // store some data
        if(typeof(Storage)!=="undefined") {
              localStorage.firstname="Dragan";
              localStorage.lastname="Gaic";           
        }
        // Change page
        $.mobile.changePage("#second");
    });   
});

$(document).on('pagebeforeshow', '#second', function(){      
    alert('My name is ' + localStorage.firstname + ' ' + localStorage.lastname);
    // Lets change localStorage data before we go to the next page
    localStorage.firstname="NewFirstNeme";
    localStorage.lastname="NewLastName";   
});

$(document).on('pagebeforeshow', '#third', function(){      
    alert('My name is ' + localStorage.firstname + ' ' + localStorage.lastname);
});

您使用的是哪个JQM版本?@Omar感谢您的回复。我使用JQM 1.3.2感谢您的回复。我遵循您的第一种方法。这里storeObject是一个全局变量??我也不明白查找“测试输入”为什么我们需要它??查看示例很高兴看到人们仍在使用我的东西:
$(document).on('pagebeforeshow', '#index', function(){      
    $(document).on('click', '#change-page-button', function(){    
        // store some data
        if(typeof(Storage)!=="undefined") {
              localStorage.firstname="Dragan";
              localStorage.lastname="Gaic";           
        }
        // Change page
        $.mobile.changePage("#second");
    });   
});

$(document).on('pagebeforeshow', '#second', function(){      
    alert('My name is ' + localStorage.firstname + ' ' + localStorage.lastname);
    // Lets change localStorage data before we go to the next page
    localStorage.firstname="NewFirstNeme";
    localStorage.lastname="NewLastName";   
});

$(document).on('pagebeforeshow', '#third', function(){      
    alert('My name is ' + localStorage.firstname + ' ' + localStorage.lastname);
});