返回到:Prototype – 元素对象
此方法收集元素的所有后代并将它们作为扩展元素数组返回。
请注意,Prototype 的所有 DOM 遍历方法都忽略文本节点并仅返回元素节点。
语法
element.descendants() ;
返回值
一组 HTML 元素。
例子
HTML
x
25
25
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showElements() {
8
var arr = $('father').descendants();
9
arr.each(function(node) {
10
alert(node.nodeName + ': ' + node.innerHTML);
11
});
12
}
13
</script>
14
</head>
15
16
<body>
17
<p>Click descendants button to see the result.</p>
18
<div id = "father">
19
<p id = "kid">This is first paragraph</p>
20
</div>
21
<br />
22
23
<input type = "button" value = "descendants" onclick = "showElements();"/>
24
</body>
25
</html>
返回到:Prototype – 元素对象
阅读剩余 39%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9126.html