返回到:Prototype – 实用方法
$A() 函数将它接收到的单个参数转换为 Array 对象。
一种建议的用途是将 DOM 节点列表转换为常规数组,这样可以更有效地遍历。
语法
$A(iterable)
返回值
数组形式的元素列表。
例子
HTML
x
28
28
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showOptions() {
8
var NodeList = $('employees').getElementsByTagName('option');
9
var nodes = $A(NodeList);
10
11
nodes.each(function(node) {
12
alert(node.nodeName + ': ' + node.innerHTML);
13
});
14
}
15
</script>
16
</head>
17
18
<body>
19
<select id = "employees" size = "10" >
20
<option value = "5">Mohtashim, Mohd</option>
21
<option value = "8">Debi, Patnaik</option>
22
<option value = "1">Madisetti, Praveen</option>
23
</select>
24
<br />
25
26
<input type = "button" value = "Show the options" onclick = "showOptions();"/>
27
</body>
28
</html>
返回到:Prototype – 实用方法
阅读剩余 43%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8954.html