JavaScript解析XML实现多级级联下拉列表
2007-10-15 16:49
746 查看
1.创建XML文档:cascaded_select.xml
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<?xml version="1.0" encoding="GBK"?>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<select>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<province key="sx" value="陕西">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<city key="xa" value="西安"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<city key="bj" value="宝鸡"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<city key="wn" value="渭南">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<xian key="fp" value="富平">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<zhen key="zq" value="张桥"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</xian>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</city>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<city key="ak" value="安康"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</province>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<province key="js" value="江苏">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<city key="nj" value="南京"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<city key="xz" value="徐州"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</province>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<province key="sh" value="上海"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</select>
2.创建BlueParseXML.js,用来加载解析XML文档
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @description 解析并封装XML
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @modifDate 2007-10-15
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//解析XML文件对象构造器
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function BlueParseXML()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.xml;//定义对象属性xml
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.loadFinish;//加载完成函数
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.nodeProperties=new Array();//节点属性数组
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.key="key";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.value="value";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.nodeList;//节点集合
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.rootName;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.XML_NULL=-1;//未加载xml,或加载失败
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//加载xml文件
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueParseXML.prototype.loadXML=function(url)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var newXML;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var obj=this;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//如果它受支持,采用标准的2级DOM技术
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(document.implementation && document.implementation.createDocument)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//创建新的Document对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
newXML=document.implementation.createDocument("","",null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//设置装载完毕时触发事件
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
newXML.onload=function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(obj.loadFinish)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
obj.loadFinish();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
newXML.load(url);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{//IE浏览器创建Document对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
newXML=new ActiveXObject("Microsoft.XMLDOM");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//设置onload
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
newXML.onreadystatechange=function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(newXML.readyState==4)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(obj.loadFinish)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
obj.loadFinish();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
newXML.load(url);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.xml=newXML;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//解析遍历xml
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueParseXML.prototype.parseXML=function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.xml==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
alert("XML未加载,请先加载XML文件!");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return parseXML.XML_NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var rootNode=this.xml.documentElement;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.rootName=rootNode.tagName;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.nodeList=new ChildNodeList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.level=this.iteratorNode(this.nodeList,rootNode,1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.level;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//遍历节点,将节点信息封装存入ChildNodeList中
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueParseXML.prototype.iteratorNode=function(list,node,level)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(!isNaN(level) && level>0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
list.nodeLevel=level;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var result=list.nodeLevel;//节点级别
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var flag=true;//判断节点是否有子节点标记
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var child=node.firstChild;child!=null;child=child.nextSibling)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
flag=false;//有子节点
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(list.nodeName==null || list.nodeName=="")...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
list.nodeName=child.tagName;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(list.nodeName==child.tagName)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var nodeInfo=new NodeInfo();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nodeInfo.nodeLevel=list.nodeLevel;//设置节点级别
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nodeInfo.nodeName=list.nodeName;//设置节点名称
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nodeInfo.key=child.getAttribute(this.key);//设置节点属性
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nodeInfo.value=child.getAttribute(this.value);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var index=0;index<this.nodeProperties.length;index++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nodeInfo[this.nodeProperties[index]]=child.getAttribute(this.nodeProperties[index]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
list.addElement(nodeInfo.key,nodeInfo);//把节点加入父节点的子节点集合
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var n=this.iteratorNode(nodeInfo.childNodeList,child,list.nodeLevel+1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(n>result)...{//如果子节点返回的节点级别大于改节点级别,设置返回节点级别为最大级别
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
result=n;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(flag)...{//当改节点没有子节点时返回的节点级别-1
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
result=result-1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return result;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//扩展String对象,增加trim方法去掉字符串前后空格
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
String.prototype.trim=function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.replace(/^s*/g,"").replace(/s*$/g,"");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @description 自定义集合对象(利用对象属性键值对,类似Hashtable使用)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @modifDate 2007-10-15
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.nodeLevel=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.nodeName;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.keyArray;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.ELEMENT_NULL=-1;//元素为空
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.ELEMENT_EXIST=-2;//元素已经存在
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.ELEMENT_NOT_EXIST=-3;//元素不存在
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.INDEX_OUT=-4//数组下标越界
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.ERROR_DELETE=-5//删除元素出错
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function ChildNodeList()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.keyArray=new Array();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//添加集合元素
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
ChildNodeList.prototype.addElement=function(key,element)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(key==null || element==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return ChildNodeList.ELEMENT_NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this[key]!=null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return ChildNodeList.ELEMENT_EXIST;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var index=this.keyArray.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.keyArray[index]=key;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this[key]=element;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return index;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//根据下标删除集合元素
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
ChildNodeList.prototype.deleteElementByIndex=function(index)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(index>=this.keyArray.length)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return ChildNodeList.INDEX_OUT;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var key=this.keyArray[index];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=index;i<this.keyArray.length;i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.keyArray[i]=this.keyArray[i+1];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.keyArray.length=this.keyArray.length-1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delete this[key];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return index;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//根据key删除集合元素
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
ChildNodeList.prototype.deleteElementByKey=function(key)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this[key]==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return ChildNodeList.ELEMENT_NOT_EXIST;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var index=0;index<this.keyArray.length;index++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.keyArray[index]==key)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.deleteElementByIndex(index);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return ChildNodeList.ERROR_DELETE;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//根据key查找元素
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
ChildNodeList.prototype.getElementByKey=function(key)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this[key];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//根据下标查找元素
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
ChildNodeList.prototype.getElementByIndex=function(index)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.getElementByKey(this.keyArray[index]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//获取集合大小
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
ChildNodeList.prototype.size=function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.keyArray.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @description 节点信息封装对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @modifDate 2007-10-15
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
NodeInfo.prototype.nodeLevel;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
NodeInfo.prototype.nodeName;//节点名称
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
NodeInfo.prototype.key;//节点名称,对应xml节点key属性
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
NodeInfo.prototype.value;//节点内容,对应xml节点value属性
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
NodeInfo.prototype.childNodeList;//子节点列表,用ChildNodeList对象封装
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//构造器
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function NodeInfo()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.childNodeList=new ChildNodeList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
3.创建BlueCasadedSelect.js文件,用来生成级联下拉框
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @description 级联下拉对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @modifDate 2007-10-15
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.selectList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.defaultValue="-1";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.defaultText="请选择…";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.nodeList;//节点总集合
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.isAddOnChangeEvent=false;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.SELECTLIST_NULL=-1;//下拉对象数组为空
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.SELECTLIST_TYPE_NOT_ARRAY=-2;//下拉对象数组不是数组对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.SELECTLIST_EMPTY=-3;//下拉对象数组为空数组
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.SELECTLIST_LENGTH_OUT=-4;//下拉对象数组小于节点集合级别
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.NODELIST_EMPTY=-5;//节点集合为空
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.EVENT_NULL=-6;//事件源为空
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//构造器
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function BlueCasadedSelect(nodeList)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nodeList!=null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.nodeList=nodeList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.nodeList=new ChildNodeList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 创建下拉列表
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModifDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param parentNode 下拉列表父节点对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param nameList 下拉列表名字集合[可选参数]
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueCasadedSelect.prototype.createSelect=function(parentNode,nameList)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nameList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.nodeList.size()>0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.createSelectDefault(parentNode,this.nodeList);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.NODELIST_EMPTY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList=new Array();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList.length=nameList.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var obj=this;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<nameList.length;i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var select=document.createElement("select");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.setAttribute("name",nameList[i]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.setAttribute("id",nameList[i]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options.length=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[0].value=this.defaultValue;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[0].text=this.defaultText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(i<nameList.length-1)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
select.attachEvent("onchange",function()...{obj.changeSelect(select);});
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.isAddOnChangeEvent=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList[i]=select;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
parentNode.appendChild(select);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.selectList.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 创建下拉列表(默认创建方法)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModifDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param parentNode 下拉列表父节点对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param nodeList XML文档节点集合
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueCasadedSelect.prototype.createSelectDefault=function(parentNode,nodeList)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList=new Array();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var obj=this;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nodeList!=null && nodeList.nodeName!=null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList.length=this.selectList.length+1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var select=document.createElement("select");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.setAttribute("name",nodeList.nodeName);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.setAttribute("id",nodeList.nodeName);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options.length=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[0].value=this.defaultValue;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[0].text=this.defaultText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList[this.selectList.length-1]=select;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
parentNode.appendChild(select);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<nodeList.size();i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var childNodeList=nodeList.getElementByIndex(i).childNodeList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(childNodeList.size()>0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
select.attachEvent("onchange",function()...{obj.changeSelect(select);});
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.isAddOnChangeEvent=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.createSelectDefault(parentNode,childNodeList);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
break;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.selectList.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 添加下拉列表onChange事件响应
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModifDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueCasadedSelect.prototype.addOnChangeEvent=function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.isAddOnChangeEvent)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.constructor!=Array)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_TYPE_NOT_ARRAY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.length<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_EMPTY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var obj=this;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<this.selectList.length-1;i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var select=this.selectList[i];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
select.attachEvent("onchange",function()...{obj.changeSelect(select);});
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.isAddOnChangeEvent=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 初始化下拉列表
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModifDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param paramList 初始化每一级下拉默认选项参数列表
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param nodeList XML文档节点集合[可选参数]
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueCasadedSelect.prototype.init=function(paramList,nodeList)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var currentList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nodeList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
currentList=this.nodeList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
currentList=nodeList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.constructor!=Array)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_TYPE_NOT_ARRAY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.length<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_EMPTY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.length<currentList.nodeLevel)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_LENGTH_OUT;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(currentList.size()<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.NODELIST_EMPTY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var select=this.selectList[currentList.nodeLevel-1];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var defaultValue=paramList[currentList.nodeLevel-1];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<currentList.size();i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var nodeInfo=currentList.getElementByIndex(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var index=select.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options.length=index+1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[index].value=nodeInfo.key;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[index].text=nodeInfo.value;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(defaultValue!=null && defaultValue==nodeInfo.key)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[index].selected=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nodeInfo.childNodeList.size()<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var j=currentList.nodeLevel;j<this.selectList.length;j++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var sel=this.selectList[j];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var n=sel.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sel.options.length=n+1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sel.options
.value=nodeInfo.key;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sel.options
.text=nodeInfo.value;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sel.options
.selected=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.init(paramList,nodeInfo.childNodeList);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return select.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 下拉列表联动
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModifDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param event 事件源下拉对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueCasadedSelect.prototype.changeSelect=function(event)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(event==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.EVENT_NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.constructor!=Array)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_TYPE_NOT_ARRAY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.length<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_EMPTY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.nodeList.size()<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.NODELIST_EMPTY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var nextList=this.nodeList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var nextSelect=event;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var flag=false;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var n=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<this.selectList.length;i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var select=this.selectList[i];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(flag)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList[i].options.length=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nextList.getElementByKey(select.value)!=null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextList=nextList.getElementByKey(select.value).childNodeList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextList=new ChildNodeList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(select==event)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect=this.selectList[i+1];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
flag=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
n=i;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nextList.size()<=0 && event.value!=this.defaultValue)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=n+1;i<this.selectList.length;i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect=this.selectList[i];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var index=nextSelect.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options.length=index+1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options[index].value=event.value;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options[index].text=event.options[event.selectedIndex].text;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options[index].selected=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return nextSelect.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<nextList.size();i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var nodeInfo=nextList.getElementByIndex(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var index=nextSelect.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options.length=index+1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options[index].value=nodeInfo.key;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options[index].text=nodeInfo.value;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return nextSelect.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
4.创建测试页面cascaded_select.html
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--深蓝忧郁级联下拉框-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<script src="BlueParseXML.js">...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
//加载XML
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<script src="BlueCasadedSelect.js">...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
//生成级联下拉
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<script>...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
function finish()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
alert("加载完成");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var myxml=new BlueParseXML();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//添加xml加载完成事件响应
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
myxml.loadFinish=finish;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
myxml.loadXML("cascaded_select.xml");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var level=myxml.parseXML();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//多级级联下拉
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var blueCasadedSelect=new BlueCasadedSelect(myxml.nodeList);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//生成下拉列表,下拉列表name属性为xml节点名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
blueCasadedSelect.createSelect(document.body);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//如果下拉列表提前已有,则不需生成,需要设置下拉列表集合为已有下拉集合,并添加onchange事件响应内容
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//blueCasadedSelect.selectList=sels;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//blueCasadedSelect.addOnChangeEvent();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
blueCasadedSelect.init(new Array("sx","xa"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//简单的树结构遍历测试
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//====================================
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
document.write("<br>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
function iterator(list)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(list.size()<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<list.size();i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var obj=list.getElementByIndex(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var j=1;j<list.nodeLevel;j++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
document.write("——");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
document.write("<a href='"+obj.key+"'>"+obj.nodeLevel+obj.value+"</a><br>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iterator(obj.childNodeList);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iterator(myxml.nodeList);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
//====================================
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<?xml version="1.0" encoding="GBK"?>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<select>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<province key="sx" value="陕西">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<city key="xa" value="西安"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<city key="bj" value="宝鸡"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<city key="wn" value="渭南">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<xian key="fp" value="富平">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<zhen key="zq" value="张桥"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</xian>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</city>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<city key="ak" value="安康"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</province>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<province key="js" value="江苏">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<city key="nj" value="南京"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<city key="xz" value="徐州"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</province>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<province key="sh" value="上海"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</select>
2.创建BlueParseXML.js,用来加载解析XML文档
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @description 解析并封装XML
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @modifDate 2007-10-15
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//解析XML文件对象构造器
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function BlueParseXML()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.xml;//定义对象属性xml
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.loadFinish;//加载完成函数
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.nodeProperties=new Array();//节点属性数组
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.key="key";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.value="value";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.nodeList;//节点集合
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.prototype.rootName;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueParseXML.XML_NULL=-1;//未加载xml,或加载失败
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//加载xml文件
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueParseXML.prototype.loadXML=function(url)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var newXML;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var obj=this;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//如果它受支持,采用标准的2级DOM技术
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(document.implementation && document.implementation.createDocument)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//创建新的Document对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
newXML=document.implementation.createDocument("","",null);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//设置装载完毕时触发事件
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
newXML.onload=function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(obj.loadFinish)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
obj.loadFinish();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
newXML.load(url);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{//IE浏览器创建Document对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
newXML=new ActiveXObject("Microsoft.XMLDOM");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//设置onload
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
newXML.onreadystatechange=function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(newXML.readyState==4)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(obj.loadFinish)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
obj.loadFinish();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
newXML.load(url);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.xml=newXML;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//解析遍历xml
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueParseXML.prototype.parseXML=function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.xml==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
alert("XML未加载,请先加载XML文件!");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return parseXML.XML_NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var rootNode=this.xml.documentElement;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.rootName=rootNode.tagName;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.nodeList=new ChildNodeList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.level=this.iteratorNode(this.nodeList,rootNode,1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.level;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//遍历节点,将节点信息封装存入ChildNodeList中
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueParseXML.prototype.iteratorNode=function(list,node,level)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(!isNaN(level) && level>0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
list.nodeLevel=level;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var result=list.nodeLevel;//节点级别
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var flag=true;//判断节点是否有子节点标记
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var child=node.firstChild;child!=null;child=child.nextSibling)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
flag=false;//有子节点
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(list.nodeName==null || list.nodeName=="")...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
list.nodeName=child.tagName;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(list.nodeName==child.tagName)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var nodeInfo=new NodeInfo();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nodeInfo.nodeLevel=list.nodeLevel;//设置节点级别
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nodeInfo.nodeName=list.nodeName;//设置节点名称
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nodeInfo.key=child.getAttribute(this.key);//设置节点属性
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nodeInfo.value=child.getAttribute(this.value);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var index=0;index<this.nodeProperties.length;index++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nodeInfo[this.nodeProperties[index]]=child.getAttribute(this.nodeProperties[index]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
list.addElement(nodeInfo.key,nodeInfo);//把节点加入父节点的子节点集合
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var n=this.iteratorNode(nodeInfo.childNodeList,child,list.nodeLevel+1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(n>result)...{//如果子节点返回的节点级别大于改节点级别,设置返回节点级别为最大级别
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
result=n;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(flag)...{//当改节点没有子节点时返回的节点级别-1
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
result=result-1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return result;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//扩展String对象,增加trim方法去掉字符串前后空格
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
String.prototype.trim=function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.replace(/^s*/g,"").replace(/s*$/g,"");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @description 自定义集合对象(利用对象属性键值对,类似Hashtable使用)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @modifDate 2007-10-15
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.nodeLevel=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.nodeName;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.keyArray;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.ELEMENT_NULL=-1;//元素为空
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.ELEMENT_EXIST=-2;//元素已经存在
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.ELEMENT_NOT_EXIST=-3;//元素不存在
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.INDEX_OUT=-4//数组下标越界
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ChildNodeList.prototype.ERROR_DELETE=-5//删除元素出错
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function ChildNodeList()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.keyArray=new Array();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//添加集合元素
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
ChildNodeList.prototype.addElement=function(key,element)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(key==null || element==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return ChildNodeList.ELEMENT_NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this[key]!=null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return ChildNodeList.ELEMENT_EXIST;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var index=this.keyArray.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.keyArray[index]=key;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this[key]=element;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return index;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//根据下标删除集合元素
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
ChildNodeList.prototype.deleteElementByIndex=function(index)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(index>=this.keyArray.length)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return ChildNodeList.INDEX_OUT;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var key=this.keyArray[index];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=index;i<this.keyArray.length;i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.keyArray[i]=this.keyArray[i+1];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.keyArray.length=this.keyArray.length-1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delete this[key];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return index;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//根据key删除集合元素
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
ChildNodeList.prototype.deleteElementByKey=function(key)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this[key]==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return ChildNodeList.ELEMENT_NOT_EXIST;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var index=0;index<this.keyArray.length;index++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.keyArray[index]==key)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.deleteElementByIndex(index);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return ChildNodeList.ERROR_DELETE;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//根据key查找元素
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
ChildNodeList.prototype.getElementByKey=function(key)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this[key];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//根据下标查找元素
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
ChildNodeList.prototype.getElementByIndex=function(index)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.getElementByKey(this.keyArray[index]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//获取集合大小
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
ChildNodeList.prototype.size=function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.keyArray.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @description 节点信息封装对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @modifDate 2007-10-15
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
NodeInfo.prototype.nodeLevel;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
NodeInfo.prototype.nodeName;//节点名称
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
NodeInfo.prototype.key;//节点名称,对应xml节点key属性
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
NodeInfo.prototype.value;//节点内容,对应xml节点value属性
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
NodeInfo.prototype.childNodeList;//子节点列表,用ChildNodeList对象封装
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//构造器
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function NodeInfo()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.childNodeList=new ChildNodeList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
3.创建BlueCasadedSelect.js文件,用来生成级联下拉框
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @description 级联下拉对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @modifDate 2007-10-15
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.selectList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.defaultValue="-1";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.defaultText="请选择…";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.nodeList;//节点总集合
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.isAddOnChangeEvent=false;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.SELECTLIST_NULL=-1;//下拉对象数组为空
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.SELECTLIST_TYPE_NOT_ARRAY=-2;//下拉对象数组不是数组对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.SELECTLIST_EMPTY=-3;//下拉对象数组为空数组
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.SELECTLIST_LENGTH_OUT=-4;//下拉对象数组小于节点集合级别
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.NODELIST_EMPTY=-5;//节点集合为空
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
BlueCasadedSelect.prototype.EVENT_NULL=-6;//事件源为空
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//构造器
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function BlueCasadedSelect(nodeList)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nodeList!=null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.nodeList=nodeList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.nodeList=new ChildNodeList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 创建下拉列表
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModifDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param parentNode 下拉列表父节点对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param nameList 下拉列表名字集合[可选参数]
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueCasadedSelect.prototype.createSelect=function(parentNode,nameList)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nameList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.nodeList.size()>0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.createSelectDefault(parentNode,this.nodeList);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.NODELIST_EMPTY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList=new Array();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList.length=nameList.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var obj=this;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<nameList.length;i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var select=document.createElement("select");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.setAttribute("name",nameList[i]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.setAttribute("id",nameList[i]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options.length=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[0].value=this.defaultValue;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[0].text=this.defaultText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(i<nameList.length-1)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
select.attachEvent("onchange",function()...{obj.changeSelect(select);});
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.isAddOnChangeEvent=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList[i]=select;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
parentNode.appendChild(select);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.selectList.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 创建下拉列表(默认创建方法)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModifDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param parentNode 下拉列表父节点对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param nodeList XML文档节点集合
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueCasadedSelect.prototype.createSelectDefault=function(parentNode,nodeList)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList=new Array();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var obj=this;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nodeList!=null && nodeList.nodeName!=null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList.length=this.selectList.length+1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var select=document.createElement("select");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.setAttribute("name",nodeList.nodeName);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.setAttribute("id",nodeList.nodeName);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options.length=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[0].value=this.defaultValue;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[0].text=this.defaultText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList[this.selectList.length-1]=select;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
parentNode.appendChild(select);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<nodeList.size();i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var childNodeList=nodeList.getElementByIndex(i).childNodeList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(childNodeList.size()>0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
select.attachEvent("onchange",function()...{obj.changeSelect(select);});
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.isAddOnChangeEvent=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.createSelectDefault(parentNode,childNodeList);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
break;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.selectList.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 添加下拉列表onChange事件响应
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModifDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueCasadedSelect.prototype.addOnChangeEvent=function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.isAddOnChangeEvent)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.constructor!=Array)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_TYPE_NOT_ARRAY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.length<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_EMPTY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var obj=this;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<this.selectList.length-1;i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var select=this.selectList[i];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
select.attachEvent("onchange",function()...{obj.changeSelect(select);});
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.isAddOnChangeEvent=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 初始化下拉列表
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModifDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param paramList 初始化每一级下拉默认选项参数列表
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param nodeList XML文档节点集合[可选参数]
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueCasadedSelect.prototype.init=function(paramList,nodeList)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var currentList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nodeList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
currentList=this.nodeList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
currentList=nodeList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.constructor!=Array)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_TYPE_NOT_ARRAY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.length<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_EMPTY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.length<currentList.nodeLevel)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_LENGTH_OUT;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(currentList.size()<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.NODELIST_EMPTY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var select=this.selectList[currentList.nodeLevel-1];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var defaultValue=paramList[currentList.nodeLevel-1];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<currentList.size();i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var nodeInfo=currentList.getElementByIndex(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var index=select.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options.length=index+1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[index].value=nodeInfo.key;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[index].text=nodeInfo.value;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(defaultValue!=null && defaultValue==nodeInfo.key)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
select.options[index].selected=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nodeInfo.childNodeList.size()<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var j=currentList.nodeLevel;j<this.selectList.length;j++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var sel=this.selectList[j];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var n=sel.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sel.options.length=n+1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sel.options
.value=nodeInfo.key;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sel.options
.text=nodeInfo.value;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sel.options
.selected=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.init(paramList,nodeInfo.childNodeList);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return select.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 下拉列表联动
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @author BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModif BluesLee
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @createDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @lastModifDate 2007-10-13
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param event 事件源下拉对象
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @version 1.0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
BlueCasadedSelect.prototype.changeSelect=function(event)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(event==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.EVENT_NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList==null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.constructor!=Array)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_TYPE_NOT_ARRAY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.selectList.length<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.SELECTLIST_EMPTY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(this.nodeList.size()<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.NODELIST_EMPTY;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var nextList=this.nodeList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var nextSelect=event;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var flag=false;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var n=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<this.selectList.length;i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var select=this.selectList[i];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(flag)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.selectList[i].options.length=1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nextList.getElementByKey(select.value)!=null)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextList=nextList.getElementByKey(select.value).childNodeList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextList=new ChildNodeList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(select==event)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect=this.selectList[i+1];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
flag=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
n=i;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(nextList.size()<=0 && event.value!=this.defaultValue)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=n+1;i<this.selectList.length;i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect=this.selectList[i];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var index=nextSelect.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options.length=index+1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options[index].value=event.value;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options[index].text=event.options[event.selectedIndex].text;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options[index].selected=true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return nextSelect.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<nextList.size();i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var nodeInfo=nextList.getElementByIndex(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var index=nextSelect.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options.length=index+1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options[index].value=nodeInfo.key;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextSelect.options[index].text=nodeInfo.value;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return nextSelect.options.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
4.创建测试页面cascaded_select.html
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--深蓝忧郁级联下拉框-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<script src="BlueParseXML.js">...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
//加载XML
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<script src="BlueCasadedSelect.js">...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
//生成级联下拉
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<script>...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
function finish()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
alert("加载完成");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var myxml=new BlueParseXML();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//添加xml加载完成事件响应
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
myxml.loadFinish=finish;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
myxml.loadXML("cascaded_select.xml");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var level=myxml.parseXML();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//多级级联下拉
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var blueCasadedSelect=new BlueCasadedSelect(myxml.nodeList);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//生成下拉列表,下拉列表name属性为xml节点名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
blueCasadedSelect.createSelect(document.body);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//如果下拉列表提前已有,则不需生成,需要设置下拉列表集合为已有下拉集合,并添加onchange事件响应内容
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//blueCasadedSelect.selectList=sels;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//blueCasadedSelect.addOnChangeEvent();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
blueCasadedSelect.init(new Array("sx","xa"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//简单的树结构遍历测试
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//====================================
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
document.write("<br>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
function iterator(list)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(list.size()<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var i=0;i<list.size();i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var obj=list.getElementByIndex(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(var j=1;j<list.nodeLevel;j++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
document.write("——");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
document.write("<a href='"+obj.key+"'>"+obj.nodeLevel+obj.value+"</a><br>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iterator(obj.childNodeList);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iterator(myxml.nodeList);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
//====================================
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
相关文章推荐
- Android开发之多级下拉列表菜单实现(仿美团,淘宝等)
- android--多级下拉列表菜单的实现
- jQuery实现多级联动下拉列表查询框
- Ajax实现级联下拉列表
- 应用Ajax技术实现无刷新的级联下拉列表
- 淘宝页面实现(包括级联菜单,下拉列表,框架)
- Android开发之多级下拉列表菜单实现(仿美团,淘宝等)
- asp.net实现省市区级联下拉列表并保存状态
- Android开发之多级下拉列表菜单实现(仿美团,淘宝等)
- Android仿美团淘宝实现多级下拉列表菜单功能
- yii 下拉列表多级联动 dropDownList 实现
- mvc用ViewData实现下拉列表的级联
- 如何在SharePoint2007中实现下拉列表(DropDownList)的级联菜单效果
- Qt5.10 用基础控件实现下拉列表菜单,可以展开多级菜单
- 使用knockoutjs 实现级联下拉列表
- Android开发之多级下拉列表菜单实现(仿美团,淘宝等)
- Android开发之多级下拉列表菜单实现(仿美团,淘宝等)
- JavaScript实现常用二级省市级联下拉列表的方法
- HTML5--(option)实现级联下拉列表
- javascript实现在下拉列表中显示多级树形菜单的方法