html頁面程式碼
<select id="tableType" name="tableType" class="select" onchange="changeSelect(this.selectedIndex)" style="width:100%;color:#3C3C3C;"> <option value="0" selected>投訴</option> <option value="1">意見</option> <option value="2">舉報</option> <option value="3">故障報修</option> <option value="4">服務申請</option> <option value="5">表揚</option> <option value="6">建議</option> <option value="7">業務諮詢</option> </select> <select id="addTable" name="addTable" style="width:100%;color:#3C3C3C;" > </select>
js程式碼
<script language="JavaScript" type="text/javascript"> /* 二級聯動下拉選單 */ var selectArray = [ //所有的 //["1","各單位各類數及總數","2","各類佔比","3","同比","4","環比","5","各單位工單件數及佔工單總數比例","6","本月屬實、不屬實工單件數及佔工單總數比例","7","不同子型別工單件數","8","故障各型別件數佔故障工單總數比例"], //投訴 ["1","各單位各類數及總數","2","各類佔比","3","同比","4","環比","5","各單位工單件數及佔工單總數比例","6","本月屬實、不屬實工單件數及佔工單總數比例","7","不同子型別工單件數","9","本月各分公司按一級分類、二級分類、三級分類統計件數","10","本月營銷類投訴、生產類投訴件數及佔投訴總數比例","11","本月一類投訴件數佔投訴總數比例、二類投訴件數佔投訴總數比例"], //意見 ["1","各單位各類數及總數","2","各類佔比","3","同比","4","環比","5","各單位工單件數及佔工單總數比例","7","不同子型別工單件數"], //舉報 ["1","各單位各類數及總數","2","各類佔比","3","同比","4","環比","5","各單位工單件數及佔工單總數比例","6","本月屬實、不屬實工單件數及佔工單總數比例","7","不同子型別工單件數"], //故障 ["1","各單位各類數及總數","2","各類佔比","3","同比","4","環比","5","各單位工單件數及佔工單總數比例","7","不同子型別工單件數","8","故障各型別件數佔故障工單總數比例"], //服務申請、建議、諮詢業務、表揚 ["1","各單位各類數及總數","2","各類佔比","3","同比","4","環比","5","各單位工單件數及佔工單總數比例"] ]; //初始化下拉選單 function initSelect(){ changeSelect(0); } function changeSelect(index){ switch(index){ case 0: break; case 1: break; case 2: break; case 3: break; case 4: break; case 5: index=4; case 6: index=4; case 7: index=4; } //選擇物件 var tableSelect1 = document.getElementById("tableType"); var tableSelect2 = document.getElementById("addTable"); tableSelect1.selectedIndex = index; //指定tableSelect2中<option>標記的個數 tableSelect2.length = selectArray[index].length / 2; //迴圈將陣列中的資料寫入<option>標記中 for (var i = 0;i<tableSelect2.length;i++) { //tableSelect2.option[i] = new Option(); //tableSelect2.option[i].text = selectArray[index][2*i+1]; //tableSelect2.option[i].value = selectArray[index][2*i]; tableSelect2[i]=new Option(selectArray[index][2*i+1],selectArray[index][2*i]); } } </script>