原型 - adjacent() 方法
此方法查找与给定选择器匹配的当前元素的所有同级元素,并将其作为数组返回。
语法
element.adjacent([ selectors...]);
返回值
HTML 元素数组。
示例
<html> <head> <title>Prototype examples</title> <script type = "text/javascript" src = "/javascript/prototype.js"></script> <script> function listCities() { var arr = $('nyc').adjacent('li.us'); arr.each(function(node) { alert(node.nodeName + ': ' + node.innerHTML); }); } </script> </head> <body> <ul id = "cities"> <li class = "us" id = "nyc">New York</li> <li class = "uk" id = "lon">London</li> <li class = "us" id = "chi">Chicago</li> <li class = "jp" id = "tok">Tokyo</li> <li class = "us" id = "la">Los Angeles</li> <li class = "us" id = "aus">Austin</li> </ul> <br /> <input type = "button" value = "List Cities" onclick = "listCities();"/> </body> </html>
输出
prototype_element_object.htm
广告