JavaScript二级级联菜单
<html> <head></head> <body> <script> //创建两个字符串 var sx = "[{'levelId':100101,'levelName':'坐席'},{'levelId':100102,'levelName':'团队长'},{'levelId':100103,'levelName':'部经理'}]"; var fw = "[{'levelId':100201,'levelName':'市场经理'},{'levelId':100202,'levelName':'市场经理助理'}]"; function changeEmpType(empTypeId){ document.getElementById("level").options.length = 0; var ob = 0; //根据人员类别决定将要把那种对象数组里面的值写入第二个SELECT中 if(empTypeId == '1001'){ //将字符串装换为对象并赋值 ob = eval("("+sx+")"); }else if(empTypeId == '1002'){ //将字符串装换为对象并赋值 ob = eval("("+fw+")"); } var option = new Option("请选择",0); if(ob != 0){ for(var j in ob){ option = new Option(ob[j].levelName,ob[j].levelId); document.getElementById("level").options.add(option); } }else{ document.getElementById("level").options.add(option); } } </script> <select name="empType" id="empType" onchange="changeEmpType(this.value)"> <option>请选择</option> <option value="1001">销售系列</option> <option value="1002">服务系列</option> </select> <select name="level" id="level"> <option>请选择</option> </select> </body> </html>
-------------------------------------------------------------------------------------
<html> <head></head> <body> <script> //创建两种类型的对象数组,sx对应销售系列,fw对应服务系列 var sx = [{'levelId':100101,'levelName':'坐席'},{'levelId':100102,'levelName':'团队长'},{'levelId':100103,'levelName':'部经理'}]; var fw = [{'levelId':100201,'levelName':'市场经理'},{'levelId':100202,'levelName':'市场经理助理'}]; function changeEmpType(empTypeId){ document.getElementById("level").options.length = 0; var ob = 0; //根据人员类别决定将要把那种对象数组里面的值写入第二个SELECT中 if(empTypeId == '1001'){ ob = sx; }else if(empTypeId == '1002'){ ob = fw; } var option = new Option("请选择",0); if(ob != 0){ for(var j in ob){ option = new Option(ob[j].levelName,ob[j].levelId); document.getElementById("level").options.add(option); } }else{ document.getElementById("level").options.add(option); } } </script> <select name="empType" id="empType" onchange="changeEmpType(this.value)"> <option>请选择</option> <option value="1001">销售系列</option> <option value="1002">服务系列</option> </select> <select name="level" id="level"> <option>请选择</option> </select> </body> </html>
相关推荐
nmgxzm00 2020-11-10
ifconfig 2020-10-14
hhanbj 2020-11-17
zfszhangyuan 2020-11-16
古叶峰 2020-11-16
一个智障 2020-11-15
jipengx 2020-11-12
81427005 2020-11-11
xixixi 2020-11-11
游走的豚鼠君 2020-11-10
苗疆三刀的随手记 2020-11-10
Web卓不凡 2020-11-03
小飞侠V 2020-11-02
帕尼尼 2020-10-30
爱读书的旅行者 2020-10-26
帕尼尼 2020-10-23
杏仁技术站 2020-10-23
淼寒儿 2020-10-22