0
我需要一些建议我怎么才能实现一个函数来检查最后一个子节点的最后一个节点的下一个节点,当我单击父节点时,它也是子节点。更具体地说,我会尝试用简单的例子更好地解释它。当我们有这样一棵树时:树中节点的非标准检查
Node1
Node9
Node11
Node15, Node14
(Node4, Node5 - Node15's children), (Node2, Node3 - Node14's children)
当我点击例如Node9,应该检查Node1,Node15,Node4和Node5元素。
我有一个函数来检查给定的父母的每个孩子节点,我想使用它,但我发现一些困难,以识别最后一个节点。是否有任何简单的方法来检查节点是否是给定路径的最后一个?
到目前为止,我有这样的事情:
function checkNonstandard(click, check) {
if(click.siblings().length>0) {
click.siblings().each(function() {
if($(this).is('ul') || $(this).is("li")) {
// if($(this).children().is(":last-child")){
// if($(this).children().length == 0){
// $(this).removeAttr('checked');
//here I wanted with no luck to put a condition to check only the next to last node with children
}
else{
checkStandard($(this).children(), check);
//this is a function to check every node for given parent and its ancestors
}
} else if($(this).is("input")) {
if(check==true) {
$(this).attr('checked', true);
} else {
$(this).removeAttr('checked');
}
}
});
}
THX提前任何建议,就如何处理它。
类似于$(this).parent()。find(“> *”) – dandavis