您的位置:首页 > 其它

二级菜单联动(自定义框架)

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: