[英]jquery help selecting parents and children at the same time, but not siblings of ancestors
我正在尝试编写一个jQuery调用,以在用户选中复选框ul菜单时选择“儿童”和“父母”。
这个jquery正确地选择了父母和孩子,但是在遍历父母时也选择了兄弟姐妹。
//Check the Parents
$(this).parents().find("input").checkUncheck(true);
//Check the Children
$(this).parent().siblings("ul").find("input").checkUncheck(true);
我不希望它在遍历祖先以选择“父母”时选择兄弟姐妹,但我不知道如何进行jquery。 如果有人对如何操作有一些提示,我将不胜感激!
谢谢。
以下是HTML:
<ul id="p_menu_nav">
<li>
<span>
<input type="checkbox" title="no">
<img images/minus.gif" class="a_hand"> Wells Fargo
</span>
<ul >
<li >
<span>
<input type="checkbox" title="no">
<img src="images/plus.gif" class="a_hand"> Southern Utah
</span>
</li>
<li >
<span>
<input type="checkbox" title="no">
<img src="images/plus.gif" class="a_hand"> Northern Utah
</span>
</li>
<li >
<span>
<input type="checkbox" title="no">
<img images/minus.gif" class="a_hand"> Central Utah
</span>
<ul >
<li>
<input type="checkbox" name="approved_property_id_list" id="4835">Apartment 1
</li>
<li>
<input type="checkbox" name="approved_property_id_list" id="4844">Apartment 10
</li>
<li>
<input type="checkbox" name="approved_property_id_list" id="4934">Apartment 100
</li>
</ul>
</li>
</ul>
</li>
</ul>
尝试这样的事情:
$(this).parents('li').find("> span > input").checkUncheck(true);
//Check the Children
$(this).closest('li').find('input').checkUncheck(true);
尝试这个 :)
$(function(){
$("#p_menu_nav input").click(function(){
var that = "#"+this.id;
$("#p_menu_nav li:has(img)").each(function(){
if($(this).contents().find(that).length > 0){
$(this).find(">span input").attr("checked",true);
}
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.