二级菜单联动(自定义框架)
2014-08-06 17:33
302 查看
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script> //自定义框架 (function(){ //命名空间的定义 if(!window['cwy']){ window['cwy']={}; } function $(id){ return document.getElementById(id); } window['cwy']['$']=$; //清除元素 function ClearElement(e){ if(e.length<=0) return; var length=e.length; for(var idx=length;idx>0;idx--) e.options[idx-1]=null; //length=e.length; } window['cwy']['ClearElement']=ClearElement; //更新元素 function UpdateElement(e,e_array){ var length=e.length; if(length!=0){ ClearElement(e); } for(var idx=0;idx<e_array.length;idx++) e.options[idx]=new Option(e_array[idx]); //length=e.length; } window['cwy']['UpdateElement']=UpdateElement; })(); window.onload=function(){ var n1=['语文','数学','英语','政治','历史','地理']; var n2=['语文','数学','英语','物理','化学','生物']; var subject=cwy.$('subject'); subject.onchange=function(){ switch(subject.value){ case 'wen':cwy.UpdateElement(cwy.$('book'),n1);break; case 'li':cwy.UpdateElement(cwy.$('book'),n2);break; default:cwy.CleaeElement(cwy.$('book'));break; } /*if(subject.value=='wen') cwy.UpdateElement(cwy.$('book'),n1); else if(subject.value=='li') cwy.UpdateElement(cwy.$('book'),n2); else cwy.ClearElement(cwy.$('book'));*/ } } </script> </head> <body> <select id="subject"> <option value="">--请选择科目--</option> <option value="wen">文科</option> <option value="li">理科</option> </select> <select id="book"> </select> </body> </html>
View Code
相关文章推荐
- Android自定义二级联动菜单
- 我的ASP之旅—二级联动菜单制作
- JavaScript实际应用:简单二级联动菜单实现
- 二级联动菜单数据库版
- 二级联动菜单详解
- 省份、县市二级联动菜单
- 实现带有数据绑定的客户端脚本控制的二级联动菜单
- .net 二级联动菜单
- 适用于已有框架的省市二级联动
- JavaScript实际应用:简单二级联动菜单实现
- 无刷新二级联动菜单的Request问题
- asp联动二级菜单
- JS结合数据库的二级联动菜单
- js二级联动菜单
- ASP.NET二级联动菜单的实现
- (转贴)实现带有数据绑定的客户端脚本控制的二级联动菜单
- 简单的二级联动菜单
- js入门·表单元素(select下拉列表)制作二级联动菜单和网站导航
- ASP.NET利用JavaScript实现无刷新闪烁二级联动菜单
- JavaScript二级联动菜单代码