- Prototype 教程
- Prototype - 主页
- Prototype - 快速概述
- Prototype - 有用的功能
- Prototype - 实用方法
- Prototype - Element 对象
- Prototype - 数字处理
- Prototype - 字符串处理
- Prototype - 数组处理
- Prototype - Hash 处理
- Prototype - 基本对象
- Prototype - 模板
- Prototype - 枚举
- Prototype - 事件处理
- Prototype - 表单管理
- Prototype - JSON 支持
- Prototype - AJAX 支持
- Prototype - 表达范围
- Prototype - 周期性执行
- Prototype 有用资源
- Prototype - 快速指南
- Prototype - 有用资源
- Prototype - 讨论
原型 - $A() 方法
函数 $A() 将它收到的单个参数转换成一个 Array 对象。
一个建议的用途是将 DOM NodeLists 转换成常规数组,这样可以更有效地遍历。
语法
$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.htm
广告