亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問JS 該怎么保存Cookie~~?

請問JS 該怎么保存Cookie~~?

PHP
白衣非少年 2019-08-17 11:11:19
JS 怎么保存Cookie~~
查看完整描述

4 回答

?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊


<!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>

 




查看完整回答
反對 回復 2019-08-18
  • 4 回答
  • 0 關注
  • 358 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號