| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3779 人关注过本帖
标题:[求助]亟亟等待求助dom添加两个元素子节点问题。。
只看楼主 加入收藏
shiyide
Rank: 2
等 级:新手上路
威 望:4
帖 子:297
专家分:0
注 册:2006-2-22
收藏
 问题点数:0 回复次数:1 
[求助]亟亟等待求助dom添加两个元素子节点问题。。

请问如何使用dom对象的appendChild方法同时添加两元素子节点,并且能显示出来,用js脚本语言写
xml代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<Address>
<Custom Sex="男">
<Name>吴梦达</Name>
<E-Mail>Mengda@sina.com</E-Mail>
</Custom>
<Custom Sex="女">
<Name>白晶晶</Name>
<E-Mail>ghost@sina.com</E-Mail>
</Custom>
</Address>

要求在客户节点添加两个元素节点“公司”“联系电话”,其中元素节点“联系电话”含有“手机”与“办公电话”两个属性节点
部分js代码如下:
<html>
<head>
<title>Enter the title of your HTML document

here</title>
</head>
<body>
<p>Enter the body text of your HTML document

here</p>
<script language="javascript">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load("Client.xml");
var cNode;
var tNode;
var mobile;
var tel;
var childs;
var i;

cNode = xmlDoc.createNode(1,"公司","");
tNode = xmlDoc.createNode(1,"联系电话","");
mobile = xmlDoc.createNode(2,"手机","");
tel = xmlDoc.createNode(2,"办公室电话","");
childs = xmlDoc.documentElement;
childs.childNodes[0].appendChild(cNode);
childs.childNodes[0].lastChild.setAttributeNode(tel);
childs.childNodes[1].appendChild(cNode);
childs.childNodes[1].lastChild.setAttributeNode(tel);

window.alert(childs.xml);
</script>
</body>
</html>

最后跳出来的窗口总是只有最后加进去的一个元素节点,不会实现两个同时显示
请高手指导

搜索更多相关主题的帖子: dom 元素子 节点 sina ghost 
2006-09-21 17:15
mordew
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2006-5-9
收藏
得分:0 

<html>
<head>
<title>Aptech</title>
</head>
<body>
<script language="javascript">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load("Client.xml");
if(xmlDoc.parseError.errorCode != 0)
window.alert(xmlDoc.parseError.reason);
else
{
var child = xmlDoc.documentElement.childNodes[0];
while(child != null)
{
var cNode = xmlDoc.createNode(1,"公司","");
var tNode = xmlDoc.createNode(1,"联系电话","");
var mobile = xmlDoc.createNode(2,"手机","");
var tel = xmlDoc.createNode(2,"办公室电话","");
child.appendChild(cNode);
child.appendChild(tNode);
child.lastChild.setAttributeNode(mobile);
child.lastChild.setAttributeNode(tel);
child = child.nextSibling;
}
window.alert(xmlDoc.documentElement.xml);
}
</script>
</body>
</html>


when we live,we should study.
2006-09-23 18:42
快速回复:[求助]亟亟等待求助dom添加两个元素子节点问题。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019134 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved