- 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
廣告