温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

04 AppCan入门学习之本地存储locStorage

发布时间:2020-07-20 13:41:31 来源:网络 阅读:1089 作者:走出地平线 栏目:开发技术

本地存储LocStorage

方法:

1.appcan.locStorage.getVal(key)  获取key保存在localStorage中对应的值

//获取保存的color

appcan.locStorage.getVal('color');//返回保存的颜色值

 

2.appcan.locStorage.setVal(key,Val)      要设置的键值对

//设置一个color到本地存储中

appcan.locStorage.setVal('color','red');

 

3.appcan.locStorage.val(key,value)     获取或者设置localStorage的值

//获取保存在localStorage中所有的key

varvalue = appcan.locStorage.val('k');//返回值是数组,包含所有的key

 

4.appcan.locStorage.remove(key)    清除localStorage中对应的值

//清除保存的颜色值

appcan.locStorage.remove('color');

5.appcan.locStorage.keys()      获取localStorage中,保存的所有键值

//获取保存在localStorage中所有的key

varkeys = appcan.locStorage.keys();//返回值是数组,包含所有的key

 

例:

Page1_content.html

添加输入框及BUTTON

<!---插入搜索输入框--->

<div class="sc-bg-active uinput ubub-f1  bc-border uba">
            <div class="uinn fafa-search sc-text"></div>
            <input placeholder="请输入搜索内容" type="text" class="ub-f1" id="textid"onblur="fun()">
        </div>
        <!--插入BUTTON-->
        <div class="btn ub ub-ac bc-text-headub-pc bc-btn umar-t"  id="btn">
            按我跳转页面并获取数据
        </div>

完成事件处理

//BUTTON事件函数
        appcan.button(".btn", "ani-act", function() {
            appcan.window.open({
                name:'showpage',
                data:'showpage.html',
                aniId:10
            });
        })
        //失去焦点函数onblur="fun()"
        function fun() {
            //获取当前页面DIV为textid的值
            var city = $("#textid").attr("value");
            //alert(city);
            //值的存储并设置id为cityId
            appcan.locStorage.setVal('cityId', city);
           
        }


Showpage_content.html

增加DIV显示
<div id="d1" class="ulev1"></div>
</body>
接收数据
appcan.ready(function() {
            //var city = appcan.locStorage.val('cityId');
            var city = appcan.locStorage.getVal("cityId");
            //alert(decodeURI(city));
            $("#d1").html(decodeURI(city)+'您好!');
           
        });



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI