Passing parameters from one page to another in jQu

2020-03-08 06:34发布

问题:

I am building a jQuery mobile application using PhoneGap. I have to open a new page by passing some parameters of perivous page using jQuery mobile. For this I have tried to use local storage, like this:

$("li").click(function(){
    console.log("hi");
    var index = $(this).index();
    console.log("index"+ index);

    window.localStorage.setItem("date",userArray_date[index] );
    window.localStorage.setItem("title",userArray_title[index] );

    window.location.href='mypage.html';     
});

On another page I retrieved values like this:

var display_date = window.localStorage.getItem("date");
var display_title = window.localStorage.getItem("title");

$("#Date_Leaf").append(display_date);
$("#Title_Leaf").append(display_title);

This is working properly on an Android phone but does not work on Windows 7 phone. Can anybody tell me where I am going am wrong please?

回答1:

http://docs.phonegap.com/en/2.0.0/cordova_storage_storage.md.html#localStorage

try use local storage in onDeviceReady function



回答2:

We Use PhoneGap deviceready method for localstorage and it work fine. like:

document.addEventListener("deviceready", myMethod, false);
function myMethod(){

$("li").click(function(){


    var index = $(this).index();

    console.log("index"+ index);

    window.localStorage.setItem("date",userArray_date[index] );
    window.localStorage.setItem("title",userArray_title[index] );

window.location.href='mypage.html';
});}

and On mypage.html:

document.addEventListener("deviceready", page2Method, false);

function page2Method(){

  var display_date = window.localStorage.getItem("date");
  var display_title = window.localStorage.getItem("title");

}