下拉框控制问题 现在我要实现两个下拉框(类似于省市级联),当我在第一个下拉框不选的时候,第二个下拉框全都可以选择,但当我第一个下拉框中选择了第一个货第二个的时候,第二个下拉框只能选择一部分的选项了.当我在第一个下拉框中选择第三个选项的时候下拉框就变灰了,什么都不能选择,想请问这个判断要如何写.(不要用struts2的标签!) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE HTML><html> <head> <meta charset="gb2312" /> <title></title> </head> <body> <select id="a"></select> <select id="b"></select> <script> function $(el){ return typeof el == 'string' ? document.getElementById(el) : el; } function $t(name, cot){ cot = cot || document; return cot.getElementsByTagName(name); } // a b 定义你的数据,a的最后一项“不可用” 那么对应 b的最后一项就不写数据。 var a = ['1', '2', '不可用']; var b = [ ['1-1', '1-2'], ['2-1', '2-2', '2-3', '2-4'] ]; for(var i = 0, len = a.length; i < len; i++){ var tmp = new Option(a[i], a[i]); $('a').add(tmp); } for(var i = 0, len = b.length; i < len; i++){ for(var j = 0, lenj = b[i].length; j < lenj; j++){ var tmp = new Option(b[i][j], b[i][j]); $('b').add(tmp); } } $('a').onchange = function(){ $('b').length = 0; var index = this.selectedIndex; if( b[index] ){ for(var i = 0, len = b[index].length; i < len; i++){ var tmp = new Option(b[index][i], b[index][i]); $('b').add(tmp); } } } </script> </body></html>楼主 这个意思? 没看懂就慢慢学http://www.w3school.com.cn/b.asp js 实现隐藏新打开的浏览器的window的图标和默认字符串 得到一个TABLE内行集合的语句,这样写怎么老出问题? 怎么监控IE7浏览器的关闭事件 网上搜不到的问题,期待高手。在微软滤镜上显示DIV(DXImageTransform.Microsoft.AlphaImageLoader) 各位帮我看下代码 jQuery挺好介绍给大家 顺便提个问 调用另一页面函数? 一个简单但很头疼的问题 ie5.0不支持window.resize吗 拖动动态生成的控件 光标跳转的问题 急!jquery如何获取子元素的value值
<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312" />
<title></title>
</head>
<body>
<select id="a"></select>
<select id="b"></select>
<script>
function $(el){
return typeof el == 'string' ? document.getElementById(el) : el;
}
function $t(name, cot){
cot = cot || document;
return cot.getElementsByTagName(name);
}
// a b 定义你的数据,a的最后一项“不可用” 那么对应 b的最后一项就不写数据。
var a = ['1', '2', '不可用'];
var b = [
['1-1', '1-2'],
['2-1', '2-2', '2-3', '2-4']
];
for(var i = 0, len = a.length; i < len; i++){
var tmp = new Option(a[i], a[i]);
$('a').add(tmp);
}
for(var i = 0, len = b.length; i < len; i++){
for(var j = 0, lenj = b[i].length; j < lenj; j++){
var tmp = new Option(b[i][j], b[i][j]);
$('b').add(tmp);
}
}
$('a').onchange = function(){
$('b').length = 0;
var index = this.selectedIndex;
if( b[index] ){
for(var i = 0, len = b[index].length; i < len; i++){
var tmp = new Option(b[index][i], b[index][i]);
$('b').add(tmp);
}
}
}
</script>
</body>
</html>楼主 这个意思?