//===============================
//
作用:選中節點對象
//
參數:
nobj node
對象
//????? cobj checkbox
對象
//===============================
dTree.prototype.checkNode = function(id,pid,_hc,checked) {
??? //1
、遞歸選父節點對象(無論是葉節點還是中間節點)
??? //
判斷同級中有無被選中的,如果有選中的就不可以反選
??? if(!this.isHaveBNode(id,pid)){
??????? if(checked){
??????????? //
選中就一直選到根節點
??????????? this.checkPNodeRecursion(pid,checked);
??????? }else{
??????????? //
去掉選中僅將其父節點去掉選中
??????????? this.checkPNode(pid,checked);
??????? }
??? }??
???
??? //2
、如果是中間結點,具有兒子,遞歸選子節點對象
?????
??? if(_hc)????
??????? this.checkSNodeRecursion(id,checked);
???
}
?
//===============================
//
作用:判斷同級中有無被選中的
//
參數:
id
節點
id
//????? pid
節點的父節點
id
//===============================
dTree.prototype.isHaveBNode = function(id,pid) {???
??? var isChecked = false
??? for (var n=0; n<this.aNodes.length; n++) {
??????? //
不是節點自身、具有同父節點兄弟節點
??????? if (this.aNodes[n].pid!=-1&&this.aNodes[n].id!=id&&this.aNodes[n].pid == pid) {?????????
??????????? if(eval("document.all."+ this.aNodes[n].cname + "_" + this.aNodes[n].id + ".checked"))
??????????????? isChecked = true;??????????
??????? }
??? }
???
??? return isChecked;
};
?
//===============================
//
作用:遞歸選中父節點對象
//
參數:
pid
節點的父節點
id
//????? ischecked
是否被選中
//===============================
dTree.prototype.checkPNodeRecursion = function(pid,ischecked) {
??? for (var n=0; n<this.aNodes.length; n++) {
??????? if (this.aNodes[n].pid!=-1&&this.aNodes[n].id == pid) {????????
??????????? eval("document.all."+ this.aNodes[n].cname + "_" + this.aNodes[n].id + ".checked = " + ischecked);
??????????? this.checkPNodeRecursion(this.aNodes[n].pid,ischecked);
??????????? break;
??????? }
??? }
};
?
//===============================
//
作用:遞歸選中子節點對象
//
參數:
id
節點
id
//????? ischecked
是否被選中
//===============================
dTree.prototype.checkSNodeRecursion = function(id,ischecked) {?
??? for (var n=0; n<this.aNodes.length; n++) {
??????? if (this.aNodes[n].pid!=-1&&this.aNodes[n].pid == id) {????????
??????????? eval("document.all."+ this.aNodes[n].cname + "_" + this.aNodes[n].id + ".checked = " + ischecked);
??????????? this.checkSNodeRecursion(this.aNodes[n].id,ischecked);?????????
??????? }
??? }
};
?
//===============================
//
作用:僅選中父節點對象
//
參數:
pid
節點的父節點
id
//????? ischecked
是否被選中
//===============================
dTree.prototype.checkPNode = function(pid,ischecked) {?
??? for (var n=0; n<this.aNodes.length; n++) {
??????? if (this.aNodes[n].pid!=-1&&this.aNodes[n].id == pid) {????????
??????????? eval("document.all."+ this.aNodes[n].cname + "_" + this.aNodes[n].id + ".checked = " + ischecked);??????????
??????????? break;
??????? }
??? }
};
|