如何从div获取innerHTML? [英] How to get innerHTML from a div?
本文介绍了如何从div获取innerHTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要保存div的innerHTML并将其存储在cookie中。这是我的基本代码。
I need to save the innerHTML of a div and store it in a cookie. Here is my basic code.
//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;
}
}
最后发生的事情是最后获得的状态已保存。我需要知道如何获取div的innerHTML。谢谢。
What ends up happening is only the last achieved status gets saved. I need to know how to get the innerHTML of the div instead. Thank you.
推荐答案
尝试一下。.
var div= document.getElementById("bottomDiv").innerHTML;
这篇关于如何从div获取innerHTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文