Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 简单cookie测试_Javascript_Html - Fatal编程技术网

Javascript 简单cookie测试

Javascript 简单cookie测试,javascript,html,Javascript,Html,如何将标记“username”显示为“John Doe”保存html代码的网站在这里, 曲奇测试 创造 删除 展示 函数创建(){ document.cookie=“username=John Doe;” } 函数ragnarok(){ document.cookie=“username=John Doe;”; } 函数showhw(){ document.getElementById(“胰腺”).innerHTML; } 我不得不声明cookie是一个变量来使用它,我这样做效率很低,但

如何将标记“username”显示为“John Doe”
保存html代码的网站在这里,

曲奇测试

创造 删除 展示

函数创建(){ document.cookie=“username=John Doe;” } 函数ragnarok(){ document.cookie=“username=John Doe;”; } 函数showhw(){ document.getElementById(“胰腺”).innerHTML; }
我不得不声明cookie是一个变量来使用它,我这样做效率很低,但却是一个快速的解决方案

 <p id="motherhome">
      Cookie test
    </p>
    <button onclick="creation()">
      Create
    </button>
    <button onclick="ragnarok()">
      Delete
    </button>
    <button onclick="showhw()">
      Display
    </button>
    <p id="pancreas">no cookie hahah</p>
    <script>
    function creation(){
      document.cookie = "username=John Doe; expires=Thu, 18 Dec 2021 12:00:00 UTC; path=/lostch1.html";
    }
    function ragnarok(){
      document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/lostch1.html";
    }
    function showhw(){
      document.getElementById("pancreas").innerHTML = username;
    }
      var username = document.cookie;
    </script>

曲奇测试

创造 删除 展示

没有饼干哈哈

函数创建(){ document.cookie=“username=John Doe;expires=Thu,2021年12月18日12:00:00 UTC;path=/lostch1.html”; } 函数ragnarok(){ document.cookie=“username=John Doe;expires=Thu,2013年12月18日12:00:00 UTC;path=/lostch1.html”; } 函数showhw(){ document.getElementById(“胰腺”).innerHTML=用户名; } var username=document.cookie;
 <p id="motherhome">
      Cookie test
    </p>
    <button onclick="creation()">
      Create
    </button>
    <button onclick="ragnarok()">
      Delete
    </button>
    <button onclick="showhw()">
      Display
    </button>
    <p id="pancreas">no cookie hahah</p>
    <script>
    function creation(){
      document.cookie = "username=John Doe; expires=Thu, 18 Dec 2021 12:00:00 UTC; path=/lostch1.html";
    }
    function ragnarok(){
      document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/lostch1.html";
    }
    function showhw(){
      document.getElementById("pancreas").innerHTML = username;
    }
      var username = document.cookie;
    </script>