首页 > 代码库 > 下拉菜单绑定代码

下拉菜单绑定代码

<script  type="text/javascript">         var emps = new Array();         emps[‘人力资源部‘] = [‘王五‘,‘朱军‘,‘张三‘,‘李四‘];         emps[‘市场部‘] = [‘刘备‘, ‘诸葛亮‘, ‘关羽‘];         emps[‘研发部‘] = [‘李妮‘,‘李俊‘,‘王明‘,‘刘忻‘];         function initDep()         {             var depObj = document.getElementById("selDepartment");             for (var index in emps)             {                 var option = document.createElement("option");                 option.text = index;                 option.value = http://www.mamicode.com/index; depObj.options.add(option); } } function fillEmps() { var empObj = document.getElementById("selEmployee");             empObj.options.length = 0;             var currentDep = document.getElementById

("selDepartment").value;             for (var index in emps[currentDep])             {                 var option = document.createElement("option");                 option.text = emps[currentDep][index];                 option.value = http://www.mamicode.com/emps[currentDep][index]; empObj.options.add(option); } } </script>

<body  onl oad="initDep(),fillEmps()">     <p>请选择姓名:</p>     部门:<select id="selDepartment" onchange="fillEmps()"></select>     姓名:<select  id="selEmployee" ></select> </body>

下拉菜单绑定代码