刚开始的js 这么写的
function OnTreeNodeChecked() {var ele = event.srcElement;if (ele.type == 'checkbox') {var childrenDivID = ele.id.replace('CheckBox', 'Nodes');var div = document.getElementById(childrenDivID);if (div != null) {var checkBoxs = div.getElementsByTagName('INPUT');for (var i = 0; i < checkBoxs.length; i++) {if (checkBoxs[i].type == 'checkbox') {checkBoxs[i].checked = ele.checked;}}}OnTreeNodeChildChecked(ele);}
}
function OnTreeNodeChildChecked(ele) {//自动处理上级 var parentDiv = ele.parentElement.parentElement.parentElement.parentElement.parentElement;var parentChkBox = document.getElementById(parentDiv.id.replace('Nodes', 'CheckBox'));if (parentChkBox != null) {var ChildsChkAll = true;var Boxs = parentDiv.getElementsByTagName('INPUT');var m = 0;var n = 0;for (var i = 0; i < Boxs.length; i++) {if (Boxs[i].type == 'checkbox') {m++;}if (Boxs[i].type == 'checkbox' && Boxs[i].checked == false) {n++}}if (m == n) {ChildsChkAll = false;}parentChkBox.checked = ChildsChkAll;OnTreeNodeChildChecked(parentChkBox);}
}}
然后 加了个catch 就完事了
function OnTreeNodeChecked() {var ele = event.srcElement;if (ele.type == 'checkbox') {var childrenDivID = ele.id.replace('CheckBox', 'Nodes');var div = document.getElementById(childrenDivID);if (div != null) {var checkBoxs = div.getElementsByTagName('INPUT');for (var i = 0; i < checkBoxs.length; i++) {if (checkBoxs[i].type == 'checkbox') {checkBoxs[i].checked = ele.checked;}}}OnTreeNodeChildChecked(ele);} } function OnTreeNodeChildChecked(ele) {//自动处理上级 try{var parentDiv = ele.parentElement.parentElement.parentElement.parentElement.parentElement;var parentChkBox = document.getElementById(parentDiv.id.replace('Nodes', 'CheckBox'));if (parentChkBox != null) {var ChildsChkAll = true;var Boxs = parentDiv.getElementsByTagName('INPUT');var m = 0;var n = 0;for (var i = 0; i < Boxs.length; i++) {if (Boxs[i].type == 'checkbox') {m++;}if (Boxs[i].type == 'checkbox' && Boxs[i].checked == false) {n++}}if (m == n) {ChildsChkAll = false;}parentChkBox.checked = ChildsChkAll;OnTreeNodeChildChecked(parentChkBox);} }catch(e){} }