返回到:Prototype – 实用方法
$A() 函数将它接收到的单个参数转换为 Array 对象。
一种建议的用途是将 DOM 节点列表转换为常规数组,这样可以更有效地遍历。
语法
$A(iterable)
返回值
数组形式的元素列表。
例子
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showOptions() {
var NodeList = $('employees').getElementsByTagName('option');
var nodes = $A(NodeList);
nodes.each(function(node) {
alert(node.nodeName + ': ' + node.innerHTML);
});
}
</script>
</head>
<body>
<select id = "employees" size = "10" >
<option value = "5">Mohtashim, Mohd</option>
<option value = "8">Debi, Patnaik</option>
<option value = "1">Madisetti, Praveen</option>
</select>
<br />
<input type = "button" value = "Show the options" onclick = "showOptions();"/>
</body>
</html>返回到:Prototype – 实用方法
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8954.html
支付宝
微信