Javascript 简单cookie测试
如何将标记“username”显示为“John Doe”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是一个变量来使用它,我这样做效率很低,但
保存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>