使用 jQuery Mobile 在页面之间传递数据? [英] Passing data between pages with jQuery Mobile?

查看:21
本文介绍了使用 jQuery Mobile 在页面之间传递数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我刚刚开始学习 jQuery Mobile,并且我已经学会了它如何通过 ajax 加载所有链接而不实际加载下一页.我的几个页面使用表单和 GET 将数据传递到下一个页面——我如何在使用 jQuery Mobile 时做到这一点?

So I've just started learning jQuery Mobile, and I've learned how it loads all links via ajax without actually loading the next page. Several of my pages use forms and GET to pass data on to the next page-- How can I do this while using jQuery Mobile?

推荐答案

我认为 JQM 很酷的一件事是您不必使用参数在页面之间传递数据.由于您与第一页在同一个 DOM 中,因此您可以使用普通的旧变量访问数据,即

One thing that I think is cool about JQM is that you don't have to use parameters to pass data between pages. Since you're in the same DOM as the first page, you can access data using plain old variables, i.e.

field1 = $('[name=field1]').val();
field2 = $('[name=field2]').val();

只要您使用 JQM 的 ajax 功能,您就可以在下一页执行以下操作:

And so long as you're using the ajax feature of JQM you could do the following in the next page:

$('.title').text(field1);

我为您制作了一个 jsfiddle 示例.

其他方法是使用 localStorage 或 sessionStorage api 或者文档中也提到了一些插件.

Other ways would be to use the localStorage or sessionStorage api or there are also some plugins mentioned in the docs.

  1. 页面参数
  2. JQM 路由器插件

这篇关于使用 jQuery Mobile 在页面之间传递数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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