function backToFar(parent) {
if(parent.length != 0){
parent.attr("checked", "true");
if ($(parent).attr("pid") != "undefined" && parent.length != 0) {
backToFar($("input[name='GoodClass'][nodeid=" + $(parent).attr("pid") + "]"));
}
}
}
//递归实现选中一个节点 下面的子节点全部选中的问题
function selectChildren(row) {
var curId = $(row).attr("nodeid");
if(curId!= undefined){
var childrens = $("input[name='GoodClass'][pid=" + curId + "]");
for (var i = 0; i < childrens.length; i++) {
var curChild = childrens[i];
$(curChild).attr("checked", "true");
selectChildren(curChild);
}
}
//for (var n = 0; n < row.children.length; n++) {
// var child = $("input[name='GoodClass'][nodeid=" + $(row.children[n]).attr("nodeid") + "]");
// child.attr("checked", "true");
// selectChildren(child);
//}
}
//递归实现一个节点取消选中,下面所有层级的节点都取消选中
function cancalChildren(row) {
if (row.attr("nodeid")!=undefined){
var childs = $("input[name='GoodClass'][pid=" + row.attr("nodeid") + "]");
for (var n = 0; n < childs.length; n++) {
var child = $("input[name='GoodClass'][nodeid=" + $(childs[n]).attr("nodeid") + "]");
if(child.length != 0){
child.removeAttr("checked");
cancalChildren(child);
}
}
}
}
//递归实现该父节点下面的所有子节点都没选中的时候父节点失去选中状态
function RemoveParSelect(row) {
var isSelect = false;
//1 保证点击按钮同级的按钮都没有选中的
if (row.attr("pid")!="undefined"){
var brorows = $("input[name='GoodClass'][pid=" + row.attr("pid") + "]");
for (var i = 0; i < brorows.length; i++) {
if ($("input[name='GoodClass'][nodeid=" + $(brorows[i]).attr("nodeid") + "]:checked").length != 0) {
isSelect = true;
break;
}
}
}
//var childs = $("input[name='GoodClass'][pid=" + row.attr("nodeid") + "]");
2 保证点击按钮的子节点全部都没有选中的 这个需要递归操作
//for (var i = 0; i < childs.length; i++) {
// var child = childs[i];
// if ($(child).attr("checked")!=undefined) {
// isSelect = true;
// break;
// }
//}
if (!isSelect) {
if (row.attr("pid")!=undefined){
var s = $("input[name='GoodClass'][nodeid=" + row.attr("pid") + "]").removeAttr("checked");
RemoveParSelect(s);
}
}
}
if(parent.length != 0){
parent.attr("checked", "true");
if ($(parent).attr("pid") != "undefined" && parent.length != 0) {
backToFar($("input[name='GoodClass'][nodeid=" + $(parent).attr("pid") + "]"));
}
}
}
//递归实现选中一个节点 下面的子节点全部选中的问题
function selectChildren(row) {
var curId = $(row).attr("nodeid");
if(curId!= undefined){
var childrens = $("input[name='GoodClass'][pid=" + curId + "]");
for (var i = 0; i < childrens.length; i++) {
var curChild = childrens[i];
$(curChild).attr("checked", "true");
selectChildren(curChild);
}
}
//for (var n = 0; n < row.children.length; n++) {
// var child = $("input[name='GoodClass'][nodeid=" + $(row.children[n]).attr("nodeid") + "]");
// child.attr("checked", "true");
// selectChildren(child);
//}
}
//递归实现一个节点取消选中,下面所有层级的节点都取消选中
function cancalChildren(row) {
if (row.attr("nodeid")!=undefined){
var childs = $("input[name='GoodClass'][pid=" + row.attr("nodeid") + "]");
for (var n = 0; n < childs.length; n++) {
var child = $("input[name='GoodClass'][nodeid=" + $(childs[n]).attr("nodeid") + "]");
if(child.length != 0){
child.removeAttr("checked");
cancalChildren(child);
}
}
}
}
//递归实现该父节点下面的所有子节点都没选中的时候父节点失去选中状态
function RemoveParSelect(row) {
var isSelect = false;
//1 保证点击按钮同级的按钮都没有选中的
if (row.attr("pid")!="undefined"){
var brorows = $("input[name='GoodClass'][pid=" + row.attr("pid") + "]");
for (var i = 0; i < brorows.length; i++) {
if ($("input[name='GoodClass'][nodeid=" + $(brorows[i]).attr("nodeid") + "]:checked").length != 0) {
isSelect = true;
break;
}
}
}
//var childs = $("input[name='GoodClass'][pid=" + row.attr("nodeid") + "]");
2 保证点击按钮的子节点全部都没有选中的 这个需要递归操作
//for (var i = 0; i < childs.length; i++) {
// var child = childs[i];
// if ($(child).attr("checked")!=undefined) {
// isSelect = true;
// break;
// }
//}
if (!isSelect) {
if (row.attr("pid")!=undefined){
var s = $("input[name='GoodClass'][nodeid=" + row.attr("pid") + "]").removeAttr("checked");
RemoveParSelect(s);
}
}
}