级联
我的是新增和修改在一个页面,所以在写的时候如果是修改就将此值显示
js:
1 changeLevel :function(systemLevel) { 2 3 var arr=new Array(); 4 arr["干线"]= ["省际一干", "省内二干"]; 5 arr["本地网"] = ["本地骨干", "本地汇聚","本地接入"]; 6 arr["集客"] = ["集客专线"]; 7 arr["驻地网"]= ["驻地网主干", "驻地网配线"]; 8 document.getElementById("system_level").options.length = 1; 9 var projectType=document.getElementById("project_type").value; 10 if(projectType!=""){ 11 12 for(var i=0;i<arr[projectType].length;i++){ 13 if(systemLevel==arr[projectType][i]){ 14 15 document.getElementById("system_level").options.add(new Option( 16 arr[projectType][i], arr[projectType][i],true,true));//后面的两个 true 是默认选中 17 }else{ 18 document.getElementById("system_level").options.add(new Option( 19 arr[projectType][i], arr[projectType][i])); 20 } 21 } 22 } 23 }
html:
1 <td class="label"><span class="text_red">*</span><label for="a0_project_type">工程类型:</label></td> 2 <td><select name="a0_project_type" data-type="required" id="project_type" data-action="changeLevel" > 3 <option value="">请选择</option> 4 <%if(duct.a0_project_type == '干线'){%> 5 <option value="干线" selected>干线</option> 6 <%}else{%> 7 <option value="干线">干线</option> 8 <%}%> 9 10 <%if(duct.a0_project_type == '本地网'){%> 11 <option value="本地网" selected>本地网</option> 12 <%}else{%> 13 <option value="本地网">本地网</option> 14 <%}%> 15 16 <%if(duct.a0_project_type == '集客'){%> 17 <option value="集客" selected>集客</option> 18 <%}else{%> 19 <option value="集客">集客</option> 20 <%}%> 21 22 <%if(duct.a0_project_type == '驻地网'){%> 23 <option value="驻地网" selected>驻地网</option> 24 <%}else{%> 25 <option value="驻地网">驻地网</option> 26 <%}%> 27 28 </select></td> 29 30 <td class="label"> 31 <span class="text_red">*</span> 32 <label for="a0_system_level">光缆级别:</label> 33 </td> 34 <td> 35 <select name="a0_system_level" data-type="required" id="system_level"> 36 <option value="">请选择</option> 37 38 <%if(duct.a0_system_level == '省际一干'){%> 39 <option value="省际一干" selected>省际一干</option> 40 <%}%> 41 <%if(duct.a0_system_level == '省内二干'){%> 42 <option value="省内二干" selected>省内二干</option> 43 <%}%> 44 <%if(duct.a0_system_level == '本地骨干'){%> 45 <option value="本地骨干" selected>本地骨干</option> 46 <%}%> 47 <%if(duct.a0_system_level == '本地汇聚'){%> 48 <option value="本地汇聚" selected>本地汇聚</option> 49 <%}%> 50 <%if(duct.a0_system_level == '本地接入'){%> 51 <option value="本地接入" selected>本地接入</option> 52 <%}%> 53 <%if(duct.a0_system_level == '集客专线'){%> 54 <option value="集客专线" selected>集客专线</option> 55 <%}%> 56 <%if(duct.a0_system_level == '驻地网主干'){%> 57 <option value="驻地网主干" selected>驻地网主干</option> 58 <%}%> 59 <%if(duct.a0_system_level == '驻地网配线'){%> 60 <option value="驻地网配线" selected>驻地网配线</option> 61 <%}%> 62 </select> 63 </td>