在 jQuery 移动应用程序中将参数从一个页面传递到另一个页面 [英] Passing parameters from one page to another in jQuery mobile application

查看:18
本文介绍了在 jQuery 移动应用程序中将参数从一个页面传递到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PhoneGap 构建一个 jQuery 移动应用程序.我必须通过使用 jQuery mobile 传递 perivous 页面的一些参数来打开一个新页面.为此,我尝试使用本地存储,如下所示:

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

这在 Android 手机上正常运行,但在 Windows 7 手机上不起作用.有人能告诉我我要去哪里错了吗?

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?

推荐答案

我们使用 PhoneGap deviceready 方法进行本地存储并且它工作正常.喜欢:

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");

}

这篇关于在 jQuery 移动应用程序中将参数从一个页面传递到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆