<html>
<title>考试申请</title>
<head>
<script type="text/javascript"> var termlist=new Array();
termlist['第一学期']=["c#","计算机基础","电子商务概论",];
termlist['第二学期']=["dreameaver","市场营销","网络","asp",];
function changeterm()
{
var term=document.getElementById("selterm").value;
var class=document.getElementById("selclass");
class.options.length=0;
for(var i in termlist)
{
if (i==term)
{
for(var j in termlist[i])
class.add(new option(termlist[i][j],null))
}
}
}</script>
</head>
<body>
<select id="selterm" onChange="changeterm()" style="width:100px">
<option>选择学期</option></select>
<select id="selclass" style="width:100px">
<option>选择课程</option>
</select>
</body>
</html>
<title>考试申请</title>
<head>
<script type="text/javascript"> var termlist=new Array();
termlist['第一学期']=["c#","计算机基础","电子商务概论",];
termlist['第二学期']=["dreameaver","市场营销","网络","asp",];
function changeterm()
{
var term=document.getElementById("selterm").value;
var class=document.getElementById("selclass");
class.options.length=0;
for(var i in termlist)
{
if (i==term)
{
for(var j in termlist[i])
class.add(new option(termlist[i][j],null))
}
}
}</script>
</head>
<body>
<select id="selterm" onChange="changeterm()" style="width:100px">
<option>选择学期</option></select>
<select id="selclass" style="width:100px">
<option>选择课程</option>
</select>
</body>
</html>
解决方案 »
- 鼠标经过弹出三级菜单,鼠标划出菜单隐藏,求大家帮忙!
- onClick("")中如何获取传参
- 推荐一款JavaScript的MVC框架Mplanet,加速前端开发
- js绑定button并设置权限
- 这个图片效果是如何实现的?能不能给个代码例子?
- 关于div的innerHTML转换问题
- 200分请教一个问题,谢谢
- 如何根据值来选中dropdownlist的某项???
- -----如何控制select框的位置-------
- 如何效验页面一个edit中填写是否为数字???
- JQuery处理ListView中绑定控件的ClientID问题,传入的值与渲染到浏览器器的ID不一致?该如何解决?
- javascript继承问题
<html>
<title>考试申请</title>
<head></head>
<body>
<select id="selterm" onChange="changeterm()" style="width:100px">
<option>选择学期</option></select>
<select id="selclass" style="width:100px">
<option>选择课程</option>
</select>
<script type="text/javascript"> var termlist = [];
termlist['第一学期'] = ["c#","计算机基础","电子商务概论"];
termlist['第二学期'] = ["dreameaver","市场营销","网络","asp"];
var tmp = [];
var obj1 = document.getElementById('selterm');
var obj2 = document.getElementById('selclass');
for(var x in termlist){
obj1.add(new Option(x, null));
tmp.push(x);
}
function changeterm(){
var l = termlist[tmp[obj1.selectedIndex - 1]];
obj2.length = 1;
for(var i = 0, len = l.length; i< len; i++){
obj2.add(new Option(l[i], null));
}
}
</script></body>
</html>
试试
<title>考试申请</title>
<head>
<script type="text/javascript">
var termlist = new Array();
termlist['第一学期'] = ["c#","计算机基础","电子商务概论"];
termlist['第二学期'] = ["dreameaver","市场营销","网络","asp"];
function changeterm() {
var term = document.getElementById('selterm').value;
var cls = document.getElementById('selclass'); //class是Javascript语言保留字,不能用作变量名
cls.options.length = 0;
for (var i in termlist) {
if (i == term) {
for(var j in termlist[i]) cls.options.add(new Option(termlist[i][j], termlist[i][j]));
}
}
}
window.onload = function() {
var obj = document.getElementById('selterm');
for(var i in termlist) obj.options.add(new Option(i, i));
}
</script>
</head>
<body>
<select id="selterm" onChange="changeterm()" style="width:100px">
<option>选择学期</option>
</select>
<select id="selclass" style="width:100px">
<option>选择课程</option>
</select>
</body>
</html>