- Prototype 教程
- Prototype - 主頁
- Prototype - 簡述
- Prototype - 有用功能
- Prototype - 實用方法
- Prototype - 元素物件
- Prototype - 數字處理
- Prototype - 字串處理
- Prototype - 陣列處理
- Prototype - 雜湊處理
- Prototype - 基本物件
- Prototype - 模板化
- Prototype - 列舉
- Prototype - 事件處理
- Prototype - 表單管理
- Prototype - JSON 支援
- Prototype - AJAX 支援
- Prototype - 表達範圍
- Prototype - 週期性執行
- Prototype 有用資源
- Prototype - 快速指南
- Prototype - 有用資源
- Prototype - 討論
Prototype - select() 方法
此方法接受任意數量的 CSS 選擇器(字串),並返回一個經過擴充套件的元素後代陣列,這些後代匹配任何選擇器。
此方法與 $$() 非常相似,但可以在一個元素的上下文中使用,而不是整個文件。支援的 CSS 語法是相同的,因此有關詳細資訊,請參閱 $$() 文件。
語法
element.select(selector...);
返回值
返回一個 HTML 元素陣列。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var arr = $('apples').select('[title = "yummy!"]');
// returns [h3, li#golden-delicious, li#mutsu]
arr.each(function(node) {
alert("First : " + node.nodeName + ': ' + node.innerHTML);
});
arr = $('apples').select( 'p#saying', 'li[title = "yummy!"]');
// returns [li#golden-delicious, li#mutsu, p#saying]
arr.each(function(node) {
alert("Second : " + node.nodeName + ': ' + node.innerHTML);
});
arr = $('apples').select('[title = "disgusting!"]');
// returns []
arr.each(function(node) {
alert("Third : " + node.nodeName + ': ' + node.innerHTML);
});
}
</script>
</head>
<body">
<p id = "test">Click the button to see the result.</p>
<ul id = "fruits">
<li id = "apples">
<h3 title = "yummy!">Apples</h3>
<ul id = "list-of-apples">
<li id = "golden" title = "yummy!" >Golden</li>
<li id = "mutsu" title = "yummy!">Mutsu</li>
<li id = "mcintosh">McIntosh</li>
<li id = "ida-red">Ida Red</li>
</ul>
<p id = "saying">An apple a day keeps the doctor away.</p>
</li>
</ul>
<input type = "button" value = "Click" onclick = "showResult();"/>
</body>
</html>
輸出
prototype_element_object.htm
廣告