当前位置: 首页 > 知识库问答 >
问题:

jQuery Mobile:通过ChangePage获取传递到页面的数据

解柏
2023-03-14

我试图将对象从一个页面传递到另一个页面,并根据JQM文档,这应该是正确的:

$.mobile.changePage( "about/us.html", { data: {paramUno:"Uno", paramDos:11} });

我的问题是,我不确定在加载后访问这些值的最佳方式us.html。我为page eshoopagebecepwaypageinitpage echange添加了页面事件回调,在每种情况下,event.data都是un定义的。正确的方法是什么?除非这是我唯一的选择,否则我宁愿不使用localStorage或全局/命名空间的var。

非常感谢。

共有1个答案

施利
2023-03-14

像这样发送它们:

$.mobile.changePage('page2.html', { dataUrl : "page2.html?parameter=123", data : { 'paremeter' : '123' }, reloadPage : true, changeHash : true });

然后这样读:

$("#index").live('pagebeforeshow', function (event, data) {
    var parameters = $(this).data("url").split("?")[1];;
    parameter = parameters.replace("parameter=","");  
    alert(parameter);    
});

更多示例可以在这里找到:jQuery Mobile:文档就绪与页面事件,只需查找章节:页面转换之间的数据/参数操作。

指数html

<!DOCTYPE html>
  <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="widdiv=device-widdiv, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <title>
    </title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js">
    </script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>  
    <script>
        $(document).on('pagebeforeshow', "#index",function () {
            $(document).on('click', "#changePage",function () {     
                $.mobile.changePage('second.html', { dataUrl : "second.html?paremeter=123", data : { 'paremeter' : '123' }, reloadPage : false, changeHash : true });
            }); 
        }); 

        $(document).on('pagebeforeshow', "#second",function () {
            var parameters = $(this).data("url").split("?")[1];;
            parameter = parameters.replace("parameter=","");  
            alert(parameter);
        });         
    </script>
   </head>
   <body>
    <!-- Home -->
    <div data-role="page" id="index">
        <div data-role="header">
            <h3>
                First Page
            </h3>
        </div>
        <div data-role="content">
          <a data-role="button" id="changePage">Test</a>
        </div> <!--content-->
    </div><!--page-->

  </body>
</html>

第二html

<!DOCTYPE html>
  <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="widdiv=device-widdiv, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <title>
    </title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js">
    </script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>  
   </head>
   <body>
    <!-- Home -->
    <div data-role="page" id="second">
        <div data-role="header">
            <h3>
                Second Page
            </h3>
        </div>
        <div data-role="content">

        </div> <!--content-->
    </div><!--page-->

  </body>
</html>

如果你想了解更多关于这个主题的信息,看看这篇文章。你会找到几个带有示例的解决方案。

 类似资料:
  • 本文向大家介绍在Js页面通过POST传递参数跳转到新页面详解,包括了在Js页面通过POST传递参数跳转到新页面详解的使用技巧和注意事项,需要的朋友参考一下 场景 最近在工作中遇到一个需求,有个页面 a.vm,对 ajax 请求的结果进行判断后,获取结果里面的数据传递给一个 URL(b.htm),跳转到新的页面 b.htm。 遇到的问题 因为一开始是 GET 请求,所以当传递的数据过大的时候,会报错

  • 我正在使用下面的查询生成器来获取在属性中使用组件(组件名称将作为参数传递)的不同页面列表。我需要传递两个参数,和path。我尝试了上面的JSON查询,但没有结果,它失败了,因为该组件可以在任何级别的页面节点上使用。例如,或 https://host:port/bin/querybuilder.json?1_property=sling:resourceType

  • 我想把一个id作为用户的输入,传递给控制器,得到特定id的数据 当我在URL--http://localhost:8080/student/1中手动传递id时,它就起作用了 Whitelabel错误页面此应用程序没有/Error的显式映射,因此您将其视为一种后退。 Wed Jun 19 11:04:22 IST 2019出现意外错误(Type=内部服务器错误,Status=500)。模板分析过程中

  • 问题内容: 我有两个页面-“页面1”和“页面2”。在第1页上,有一个文本框,其值例如为100,最后是一个按钮。 通过按下按钮,我希望javascript将文本框的值保存在全局(?)变量中,然后跳转到第2页。使用“ window.onload”,我想要第二个Javascript函数来提醒保存在page1的值。 这是我的Javascript代码: 在“页面1”上,我有一个带有以下内容的发送按钮: 它启

  • 本文向大家介绍用js通过url传参把数据从一个页面传到另一个页面,包括了用js通过url传参把数据从一个页面传到另一个页面的使用技巧和注意事项,需要的朋友参考一下 用js把数据从一个页面传到另一个页面的层里? 如果是传到新页面的话,你网站基于什么语言开发直接用get或者post获取,然后输出到这个层 通过url传参 如果是HTML页面的话JS传到新页面就window.location.href='

  • 在普通的web开发中,参数传递有这么几种形式: url: /another_page?id=3 表单: <form>...</form> 在vuejs中,不会产生表单的提交(这会引起页面的整体刷新). 所以有两种: url . 同传统语言. vuejs 内部的机制.(无法在url 中体现,可以认为是由js代码隐式实现的) 我们用一个实际的例子说明. 我们之前实现了 "博客列表页",接下来我们要实现