【问题标题】:Passing parameters from one page to another in jQuery mobile application在 jQuery 移动应用程序中将参数从一个页面传递到另一个页面
【发布时间】:2012-08-16 04:47:30
【问题描述】:

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

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

在另一个页面上,我检索到这样的值:

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 手机上无法正常工作。谁能告诉我我要去哪里错了吗?

【问题讨论】:

  • 即使我尝试使用 $.mobile.changePage('mypage.html?date'=dispaly_date);但是 windows 模拟器在加载页面时显示错误。

标签: jquery windows-phone-7 jquery-mobile cordova


【解决方案1】:

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

尝试在 onDeviceReady 函数中使用本地存储

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-02
      • 2016-01-24
      • 1970-01-01
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多