返回到:Prototype – 元素对象
此方法检查元素是否是祖先的后代。
由于 Element.descendantOf 在内部将 $() 应用于祖先,它无差别地接受一个元素或一个元素的 id 作为它的第二个参数。
语法
element.descendantOf(ancestor);
返回值
如果它发现该元素是祖先的后代,则返回 true,否则返回 false。
例子
<html> <head> <title>Prototype examples</title> <script type = "text/javascript" src = "/javascript/prototype.js"></script> <script> function isDescendant() { var father = $('father'); var kid = $('kid'); // This is correct relationship and will be printed if( kid.descendantOf(father) ) { alert( "Kid is descendant of father" ); } // This is wrong relationship and will not be printed if( father.descendantOf(kid) ) { alert( "Father is descendant of kid" ); } } </script> </head> <body> <p>Click isDescendant button to see the result.</p> <div id = "grandfather"> <div id = "father"> <div id = "kid"></div> </div> </div> <br /> <input type = "button" value = "isDescendant" onclick = "isDescendant();"/> </body> </html>
返回到:Prototype – 元素对象
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9129.html