應用XML 可以輕松實現以往JS 實現起來較複雜的多級聯動的實例, < select name = year ></ select > < select name = month ></ select > < select name = date ></ select > < select name = clock ></ select > < input name = result > < script > // arrSel定义了要修改的下拉框和xml数据的节点名称 var arrSel = [ " year " , " month " , " date " , " clock " ]; </ script > < xml id = xmldata > < xmldata > < year value = " 2000 " > < month value = " 4 " > < date value = " 14 " > < clock value = " 一点 " /> < clock value = " 三点 " /> </ date > < date value = " 17 " > < clock value = " 一点 " /> </ date > </ month > < month value = " 5 " > < date value = " 15 " > < clock value = " 一点 " /> < clock value = " 四点 " /> < clock value = " 七点 " /> </ date > </ month > </ year > < year value = " 2001 " > < month value = " 7 " > < date value = " 16 " > < clock value = " 一点 " /> < clock value = " 五点 " /> < clock value = " 九点 " /> </ date > </ month > </ year > </ xmldata > </ xml > < script > function qswhXml(num)... ... { var i,j,arrTemp=[]; for(i=0;i<num;i++) arrTemp[i]=document.all(arrSel[i]).options[document.all(arrSel[i]).selectedIndex].text if(num==arrSel.length) ......{ //这里处理最后的数据 document.all("result").value="您中了("+arrTemp+")";return; } //document.all(arrSel[num]) 這個是選取某個Option而設,跟下面這句聯用 :options[length++].text=obj.childNodes[i].getAttribute("value"); with(document.all(arrSel[num])) ......{ length=0 var obj=document.all.xmldata.XMLDocument.childNodes[0]; for(i=0;i<num;i++) obj=obj.selectSingleNode(arrSel[i]+'[@value="'+arrTemp[i]+'"]'); // 要一級一級往下搜索選用For 方式進行遞歸選取 // 如用if 則得具體指定它的路徑,如: objNode.SelectSingleNode(“/Company/Department/Employees/Employee”) //if(num>0) // obj=obj.selectSingleNode(arrSel[num-1]+'[@value="'+arrTemp[num-1]+'"]'); for(i=0;i<obj.childNodes.length;i++) options[length++].text=obj.childNodes[i].getAttribute("value"); onchange=new Function("qswhXml("+(num+1)+")"); onchange(); }} qswhXml( 0 ); </ script >