<head>
</head>
<body>
<?xml version="1.0" encoding="gb2312"?>
<xml id="Login">
<Students name="98班级">
<Student name="王小平">
<Chinese id="語文">
<Item id="单选题">
<Score id="33"></Score>
<Score id="33"></Score>
<Score id="33"></Score>
</Item>
<Item id="多选题">
<Score id="33"></Score>
</Item>
<Item id="计算题">
<Score id="33"></Score>
</Item>
<Item id="应用题">
<Score id="33"></Score>
</Item>
<Item id="附加题">
<Score id="33"></Score>
</Item>
</Chinese>
<Physics id="物理"></Physics>
<English id="英語"></English>
<Geography id="地理"></Geography>
<Historical id="歷史"></Historical>
</Student>
<Student name="孟雲江">
<Chinese id="語文"></Chinese>
<Physics id="物理"></Physics>
<English id="英語"></English>
<Geography id="地理"></Geography>
<Historical id="歷史"></Historical>
</Student>
<Student name="胡光">
<Chinese id="語文"></Chinese>
<Physics id="物理"></Physics>
<English id="英語"></English>
<Geography id="地理"></Geography>
<Historical id="歷史"></Historical>
</Student>
</Students>
</xml>
</xml>
<head></head>
<script>
var Box = function (){}
var Tree = function ()
{
this.create = function (level,xml)
{
var space = "";
for(var i=0;i<level;i++)
{
space += " ";
}
if(level != 0)
document.body.innerHTML += space + xml.attributes[0].value +"<BR>";
for(var i=0;i< xml.childNodes.length;i++)
{
if(xml.childNodes[i].childNodes.length>0)
{
this._tree = new Box();
Tree.apply(this._tree);
this._tree.create(level+1,xml.childNodes[i]);
}
else
{
document.body.innerHTML += space + xml.childNodes[i].attributes[0].value +"<BR>";
}
}
}
}var tree = new Box();
Tree.apply(tree);
tree.create(0,Login.documentElement);
</script>
</body>
上面的代码,我想实现每隔 1 秒读出一个 xml节点并输出到屏幕上(innerHTML),不知道应怎样设置 settimeout 请大家帮忙,谢谢
</head>
<body>
<?xml version="1.0" encoding="gb2312"?>
<xml id="Login">
<Students name="98班级">
<Student name="王小平">
<Chinese id="語文">
<Item id="单选题">
<Score id="33"></Score>
<Score id="33"></Score>
<Score id="33"></Score>
</Item>
<Item id="多选题">
<Score id="33"></Score>
</Item>
<Item id="计算题">
<Score id="33"></Score>
</Item>
<Item id="应用题">
<Score id="33"></Score>
</Item>
<Item id="附加题">
<Score id="33"></Score>
</Item>
</Chinese>
<Physics id="物理"></Physics>
<English id="英語"></English>
<Geography id="地理"></Geography>
<Historical id="歷史"></Historical>
</Student>
<Student name="孟雲江">
<Chinese id="語文"></Chinese>
<Physics id="物理"></Physics>
<English id="英語"></English>
<Geography id="地理"></Geography>
<Historical id="歷史"></Historical>
</Student>
<Student name="胡光">
<Chinese id="語文"></Chinese>
<Physics id="物理"></Physics>
<English id="英語"></English>
<Geography id="地理"></Geography>
<Historical id="歷史"></Historical>
</Student>
</Students>
</xml>
</xml>
<head></head>
<script>
var Box = function (){}
var Tree = function ()
{
this.create = function (level,xml)
{
var space = "";
for(var i=0;i<level;i++)
{
space += " ";
}
if(level != 0)
document.body.innerHTML += space + xml.attributes[0].value +"<BR>";
for(var i=0;i< xml.childNodes.length;i++)
{
if(xml.childNodes[i].childNodes.length>0)
{
this._tree = new Box();
Tree.apply(this._tree);
this._tree.create(level+1,xml.childNodes[i]);
}
else
{
document.body.innerHTML += space + xml.childNodes[i].attributes[0].value +"<BR>";
}
}
}
}var tree = new Box();
Tree.apply(tree);
tree.create(0,Login.documentElement);
</script>
</body>
上面的代码,我想实现每隔 1 秒读出一个 xml节点并输出到屏幕上(innerHTML),不知道应怎样设置 settimeout 请大家帮忙,谢谢
<head>
</head>
<body>
<?xml version="1.0" encoding="gb2312"?>
<xml id="Login">
<Students name="98班级">
<Student name="王小平">
<Chinese id="語文">
<Item id="单选题">
<Score id="33"></Score>
<Score id="33"></Score>
<Score id="33"></Score>
</Item>
<Item id="多选题">
<Score id="33"></Score>
</Item>
<Item id="计算题">
<Score id="33"></Score>
</Item>
<Item id="应用题">
<Score id="33"></Score>
</Item>
<Item id="附加题">
<Score id="33"></Score>
</Item>
</Chinese>
<Physics id="物理"></Physics>
<English id="英語"></English>
<Geography id="地理"></Geography>
<Historical id="歷史"></Historical>
</Student>
<Student name="孟雲江">
<Chinese id="語文"></Chinese>
<Physics id="物理"></Physics>
<English id="英語"></English>
<Geography id="地理"></Geography>
<Historical id="歷史"></Historical>
</Student>
<Student name="胡光">
<Chinese id="語文"></Chinese>
<Physics id="物理"></Physics>
<English id="英語"></English>
<Geography id="地理"></Geography>
<Historical id="歷史"></Historical>
</Student>
</Students>
</xml>
</xml>
<head></head>
<script>
var info=[];//先将递归遍历得到的结果存入该数组,等遍历结束在每隔1s显示
var index=0;
var showInfo=function () {
if (info[index]) {
document.body.innerHTML +=info[index];
index++;
setTimeout(showInfo,1000);
}
}
var Box = function (){}
var Tree = function ()
{
this.create = function (level,xml)
{
var space = "";
for(var i=0;i<level;i++)
{
space += " ";
}
if(level != 0)
//document.body.innerHTML += space + xml.attributes[0].value +"<BR>";
info.push(space + xml.attributes[0].value +"<BR>");
for(var i=0;i< xml.childNodes.length;i++)
{
if(xml.childNodes[i].childNodes.length>0)
{
this._tree = new Box();
Tree.apply(this._tree);
this._tree.create(level+1,xml.childNodes[i]);
}
else
{
//document.body.innerHTML += space + xml.childNodes[i].attributes[0].value +"<BR>";
info.push(space + xml.childNodes[i].attributes[0].value +"<BR>");
}
}
}
}
var tree = new Box();
Tree.apply(tree);
tree.create(0,Login.documentElement);
setTimeout(showInfo,1000);
</script>
</body>