我正在實現jQuery,並在我的代碼庫中取出Prototype庫,我想知道是否可以給我最好的方法來實現此功能jQuery的。 我熟悉jQuery祖先>
後代的語法,但只是想檢查一個元素是否爲真的後代,如下面的代碼: 有人可以給我最有效的jQuery解決方案嗎?找出元素是否是另一個後裔的最佳方法
<div id="australopithecus">
<div id="homo-herectus">
<div id="homo-sapiens"></div>
</div>
</div>
$('homo-sapiens').descendantOf('australopithecus');
// -> true
$('homo-herectus').descendantOf('homo-sapiens');
// -> false
重複數據刪除:http://stackoverflow.com/questions/865486/how-can-i-check-if-an-element-is-within-another-one-in-jquery/865551 – 2009-06-29 17:35:33
使用` jQuery.contains()`。請參閱下面的答案。 – TLindig 2013-10-01 13:25:09