如何在jQM页面之间存储变量? [英] How-to store variable beetween jQM pages?

查看:160
本文介绍了如何在jQM页面之间存储变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在两个jQueryMobile页面之间传递像username这样的变量?

How do I pass a variable like username between two jQueryMobile pages?

或两个常规页面,将变量视为全局不起作用,因为at下一个包含它会将变量设置回null。

or two regular pages for that matter, having the variable as global does not work, since at the next include it will set the variable back to null.

如何在两个html页面之间传递变量全局变量?

How do I pass a variable a global variable between two html pages?

推荐答案

我通常使用本地存储,也可以存储对象。例如:

I usually go with local storage, you can store objects too. Ex:

var userInfo = {
            "username": "Bob",
            "roleName": "Admin",
            "image": "img/userPic.jpg",
        };

        //Store the object in local storage
        localStorage.setItem('loggedUser', JSON.stringify(userInfo));

然后在另一页上你可以做到:

then on the other page you can simply do:

var userInfo = JSON.parse(localStorage.getItem("loggedUser"));
var userName = userInfo.username;

这篇关于如何在jQM页面之间存储变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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