Zer*_*ter 5 html javascript cookies innerhtml
我需要保存 div 的 innerHTML 并将其存储在 cookie 中。这是我的基本代码。
//The div-saving function
function addStatus(sName){
getElement("bottomDiv").innerHTML += sName + "<br>";
document.cookie="status=" + sName + "<br>";
}
//The button clicking function
function clk(){
num++;
document.cookie = "num=" + num;
switch(num){
case 25:
addStatus("25: Alright! Let the games begin!");
break;
case 50:
addStatus("50: Woah! Getting into the high numbers!");
break;
}
}
Run Code Online (Sandbox Code Playgroud)
最终发生的只是最后达到的状态被保存。我需要知道如何获取 div 的innerHTML。谢谢你。
尝试这个..
var div= document.getElementById("bottomDiv").innerHTML;
Run Code Online (Sandbox Code Playgroud)