原生js输入框本地储存多条数据

原生js输入框本地储存多条数据,第1张

可以使用LocalStorage API来储存本地数据可以使用setItem()方法将多条数据保存到本地。可以将多条数据转换为JSON格式或其他格式,然后使用setItem方法将其存储到 LocalStorage 中。

使用cookie即可。

<!DOCTYPE HTML>

<html lang="en-US">

<head>

<meta charset="UTF-8">

<meta name="keywords" content="白菜编辑部">

<title>白菜编辑部</title>

<style type="text/css">

</style>

<script type="text/javascript">

    function readCookie (name)

    {

        var cookieValue = ""

        var search = name + "="

        if (document.cookie.length > 0)

        {

            offset = document.cookie.indexOf (search)

            if (offset != -1)

            {

                offset += search.length

                end = document.cookie.indexOf ("", offset)

                if (end == -1)

                    end = document.cookie.length

                cookieValue = unescape (document.cookie.substring (offset, end))

            }

        }

        return cookieValue

    }

    function writeCookie (name, value, hours)

    {

        var expire = ""

        if (hours != null)

        {

            expire = new Date ((new Date ()).getTime () + hours * 3600000)

            expire = " expires=" + expire.toGMTString ()

        }

        document.cookie = name + "=" + escape (value) + expire

    }

     

    writeCookie ("myCookie", "my name", 24)

    alert (readCookie ("myCookie"))

</script>

</head>

<body>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/6662623.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-26
下一篇 2023-03-26

发表评论

登录后才能评论

评论列表(0条)

保存