首页 > 其他 > 详细

页面缓存、离线存储技术localforage(案例篇)

时间:2019-11-01 00:55:35      阅读:130      评论:0      收藏:0      [点我收藏+]

localforage案例使用

通过简单的案例使用,让大家可以快速上手使用localforage

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>离线存储localforage</title>
        <script src="https://cdn.bootcss.com/localforage/1.7.3/localforage.min.js"></script>
    </head>
    <body>
        <br>
        <span id="s1" title="第1个存储的数据"></span>
        <input type="text" id="t1" placeholder="请输入第1个要存储的数据">
        <button type="button" onclick="t1()">点击存储</button>
        <br><br><br>
        <span id="s2" title="第2个存储的数据"></span>
        <input type="text" id="t2" placeholder="请输入第2个要存储的数据">
        <button type="button" onclick="t2()">点击存储</button>
        <br>
    </body>
    
    <script type="text/javascript">
        function t1(){
            let text = document.getElementById("t1").value;
            localforage.setItem('t1', text).then(function (value) {
                // 当值被存储后,可执行其他操作
                console.log(value);
            }).catch(function(err) {
                // 当出错时,此处代码运行
                console.log(err);
            });
        }
        function t2(){
            let text = document.getElementById("t2").value;
            localforage.setItem('t2', text).then(function (value) {
                // 当值被存储后,可执行其他操作
                console.log(value);
            }).catch(function(err) {
                // 当出错时,此处代码运行
                console.log(err);
            });
        }
    </script>
</html>

页面缓存、离线存储技术localforage(案例篇)

原文:https://www.cnblogs.com/caominjie/p/11774607.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!