Prototype - $A() 方法
$A() 函数将其接收的单个参数转换为 Array 对象。
建议的一种用法是将 DOM NodeList 转换为常规数组,这样可以更有效地遍历。
语法
$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_utility_methods.html