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