- XML DOM 基础
- XML DOM - 首页
- XML DOM - 概述
- XML DOM - 模型
- XML DOM - 节点
- XML DOM - 节点树
- XML DOM - 方法
- XML DOM - 加载
- XML DOM - 遍历
- XML DOM - 导航
- XML DOM - 访问
- XML DOM 操作
- XML DOM - 获取节点
- XML DOM - 设置节点
- XML DOM - 创建节点
- XML DOM - 添加节点
- XML DOM - 替换节点
- XML DOM - 移除节点
- XML DOM - 克隆节点
- XML DOM 对象
- DOM - 节点对象
- DOM - 节点列表对象
- DOM - 已命名节点映射对象
- DOM - DOMImplementation
- DOM - DocumentType 对象
- DOM - 处理指令
- DOM - 实体对象
- DOM - 实体引对象
- DOM - 符号对象
- DOM - 元素对象
- DOM - 属性对象
- DOM - CDATASection 对象
- DOM - 注释对象
- DOM - XMLHttpRequest 对象
- DOM - DOMException 对象
- XML DOM 实用资源
- XML DOM - 快速指南
- XML DOM - 实用资源
- XML DOM - 讨论
DOM - 节点对象属性 - firstChild
firstChild 属性指定节点的第一个子节点。
语法
以下是使用 firstChild 属性的语法。
nodeObject.firstChild
示例
node.xml 内容如下:
<?xml version = "1.0"?>
<Company>
<Employee category = "Technical">
<FirstName>Tanmay</FirstName>
<LastName>Patil</LastName>
<ContactNo>1234567890</ContactNo>
<Email>tanmaypatil@xyz.com</Email>
</Employee>
<Employee category = "Non-Technical">
<FirstName>Taniya</FirstName>
<LastName>Mishra</LastName>
<ContactNo>1234667898</ContactNo>
<Email>taniyamishra@xyz.com</Email>
</Employee>
<Employee category = "Management">
<FirstName>Tanisha</FirstName>
<LastName>Sharma</LastName>
<ContactNo>1234562350</ContactNo>
<Email>tanishasharma@xyz.com</Email>
</Employee>
</Company>
以下示例演示了 firstChild 属性的使用 -
<!DOCTYPE html>
<html>
<body>
<script>
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","/dom/node.xml",false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
function get_firstChild(p) {
a = p.firstChild;
while (a.nodeType!=1) {
a = a.nextSibling;
}
return a;
}
x = get_firstChild(xmlDoc.getElementsByTagName("Employee")[0]);
document.write("First child is : ");
document.write(x.nodeName);
</script>
</body>
</html>
执行
将此文件另存为服务器路径上的 nodeattribute_firstchild.htm(此文件和 node.xml 应在服务器上的同一路径中)。我们将获得如下输出 -
First child is : FirstName
dom_node_object.htm
广告