JavaScript: 复制代码代码如下: <BR>var level1 = ["北京"、"広州"、"上海"]; <BR>var level2 = [["趙陽"、"天壇"、"古公"]、["天河"、"番禺"]、["浦東"、"浦西"]]; <BR>var level3 = [[["TianShan", "HuangShan"], ["TianTan1", "TianTan2"], ["GuGong1", "GuGong2", "GuGong3", "GuGong4"]], [[" TianHe1", "TianHe2"], ["PanYu1", "PanYu2"]], [["PuDong1", "PuDong2"], ["PuXi1", "PuXi2"]]]; <BR>var Levels = { <BR>fL: null,//各階層選択用 DOM 参照 <BR>sL: null, <BR>tL: null, <BR>l1: null, <BR>l2: null, <BR>l3: null, <BR>$: function(id){ <BR>return (typeof id == "object") ? id : document.getElementById(id); <BR>}, <BR>init: function(fID, sID, tID, l1, l2, l3){ <BR>this.fL = this.$(fID); <BR>this.sL = this.$(sID); <BR>this.tL = this.$(tID); <BR>this.l1 = l1; <BR>this.l2 = l2; <BR>this.l3 = l3; <BR>this.fL.options.add(new Option("Select",-1));//给一级菜单追加一个“select”标志<BR>for (var i = 0; i < l1.長さ; i ) { <BR>var item = new Option(l1[i], i); <BR>this.fL.options.add(item); <BR>} <BR>this.doLev2(); //调用doLev2関数数,处理二级菜单 <BR>this.doLev3(); //用doLev3関数数,处理三级菜单 <BR>}, <BR>removeSTL: function(){ //第二、三级的菜单项用 <BR>this.sL.options.length = 0; <BR>this.tL.options.length = 0; <BR>}, <BR>removeTL: function(){ //第三级の菜单项を削除するために使用されます <BR>this.tL.options.length = 0; <BR>}, <BR>doLev2: function(){ //处理二级菜单 <BR>var that = this; <BR>this.fL.onchange = function(){ <BR>that.removeSTL(); //删旧秒の選択 <BR>if (that.fL.selectedIndex == 0) { <BR>that.removeSTL(); // //删除旧二番目のselect <BR>} <BR>else { <BR>that.sL.options.add(new Option("Select", -1)); //第二階層菜单追加「select」标志 <BR>//第二階層に必要な数組 <BR>var items = that.l2[that.fL.selectedIndex - 1]; <BR>for (var i = 0; i <items.length; i ) { //第二段追加の新選択项 <BR>var item = new Option(items[i], i); <BR>that.sL.options.add(item); <BR>} <BR>} <BR>} <BR>}, <BR>doLev3: function(){ //处理三级菜单 <BR>var that = this; <BR>this.sL.onchange = function(){ <BR>that.removeTL(); //删旧三番目の選択 <BR>if (that.sL.selectedIndex == 0) { <BR>that.removeTL(); //删削除旧 third の select <BR>} <BR>else { <BR>that.tL.options.add(new Option("Select", -1)); //第三階層菜单追加「select」标志 <BR>//第三階層に必要な数組を取得 <BR>var items = that.l3[that.fL.selectedIndex - 1][that.sL.selectedIndex - 1]; <BR>for (var i = 0; i <items.length; i ) { //第三级の新選択项を追加 <BR>var item = new Option(items[i], i); <BR>that.tL.options.add(item); <BR>} <BR>} <BR>} <BR>} <BR>} <BR>onload = function(){ <BR>Levels.init("first", "second", "three", level1,レベル2、レベル3); //レベル用の init メソッド <BR>} <BR> HTML: 复制代代码如下: < ;フォーム> 演示代: ç¡é¡ã®ããã¥ã¡ã³ã [Ctrl A å ¨é注:å¦ãå¿ è¦åå ¥å¤é¨Jså¿ è¦å·æ°æè½æ§è¡] var level1 = ["Beijing", "GuangZhou", "ShangHai"]; var level2 = [["ZhaoYang", "TianTan", "GuGong"], ["Tianhe", "Panyu"], ["PuDong", "PuXi"]]; var level3 = [[["TianShan", "HuangShan"], ["TianTan1", "TianTan2"], ["GuGong1", "GuGong2", "GuGong3", "GuGong4"]], [["TianHe1", "TianHe2"], ["PanYu1", "PanYu2"]], [["PuDong1", "PuDong2"], ["PuXi1", "PuXi2"]]]; var Levels = { fL: null,//ç¨åå¨å级selectçDOMå¼ç¨ sL: null, tL: null, l1: null, l2: null, l3: null, $: function(id){ return (typeof id == "object") ? id : document.getElementById(id); }, init: function(fID, sID, tID, l1, l2, l3){ this.fL = this.$(fID); this.sL = this.$(sID); this.tL = this.$(tID); this.l1 = l1; this.l2 = l2; this.l3 = l3; this.fL.options.add(new Option("Select",-1));//ç»ä¸çº§èåæ·»å ä¸ä¸ª"select"æ å¿ for (var i = 0; i < l1.length; i++) { var item = new Option(l1[i], i); this.fL.options.add(item); } this.doLev2(); //è°ç¨doLev2å½æ°ï¼å¤çäºçº§èå this.doLev3(); //è°ç¨doLev3å½æ°ï¼å¤çä¸çº§èå }, removeSTL: function(){ //ç¨äºå é¤ç¬¬äºãä¸çº§çèå项 this.sL.options.length = 0; this.tL.options.length = 0; }, removeTL: function(){ //ç¨äºå é¤ç¬¬ä¸çº§çèå项 this.tL.options.length = 0; }, doLev2: function(){ //å¤çäºçº§èå var that = this; this.fL.onchange = function(){ that.removeSTL(); //å é¤æ§secondçselect if (that.fL.selectedIndex == 0) { that.removeSTL(); // //å é¤æ§secondçselect } else { that.sL.options.add(new Option("Select", -1)); //ç»äºçº§èåæ·»å ä¸ä¸ª"select"æ å¿ //è·å第äºçº§æéçæ°ç» var items = that.l2[that.fL.selectedIndex - 1]; for (var i = 0; i < items.length; i++) { //æ·»å 第äºçº§çæ°select项 var item = new Option(items[i], i); that.sL.options.add(item); } } } }, doLev3: function(){ //å¤çä¸çº§èå var that = this; this.sL.onchange = function(){ that.removeTL(); //å é¤æ§thirdçselect if (that.sL.selectedIndex == 0) { that.removeTL(); //å é¤æ§thirdçselect } else { that.tL.options.add(new Option("Select", -1)); //ç»ä¸çº§èåæ·»å ä¸ä¸ª"select"æ å¿ //è·å第ä¸çº§æéçæ°ç» var items = that.l3[that.fL.selectedIndex - 1][that.sL.selectedIndex - 1]; for (var i = 0; i < items.length; i++) { //æ·»å 第ä¸çº§çæ°select项 var item = new Option(items[i], i); that.tL.options.add(item); } } } } } onload = function(){ Levels.init("first", "second", "third", level1,level2,level3); //è°ç¨Levelsçinitæ¹æ³ }