| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 684 人关注过本帖
标题:求大神指点,js 做三级联下拉菜单,第三个下拉菜单没反应额
只看楼主 加入收藏
我爱敲代码
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:70
专家分:165
注 册:2013-4-23
结帖率:85.71%
收藏
已结贴  问题点数:20 回复次数:1 
求大神指点,js 做三级联下拉菜单,第三个下拉菜单没反应额






图片附件: 游客没有浏览图片的权限,请 登录注册
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function change(){
    var provinceList=new Array();
    provinceList['中国']=["浙江","江苏","福建"];
    provinceList['美国']=["aa","bb"];
    provinceList['英国']=["dd","ee"];
    var province=document.forms[0].province;
    province.options.length=0;
    var index=document.forms[0].country.value;
    province.options.length=0;
    for(var j in provinceList[index]){
        newOption=new Option(provinceList[index][j],provinceList[index][j]);
        province.options.add(newOption);
    }
}
function changeCity(){
    alert(123);
        var cityList=new Array();
        cityList['浙江']=["杭州","宁波","温州","绍兴","金华","湖州","嘉兴"];
        cityList['江苏']=["南京","苏州","徐州","无锡","常州","镇江"];
        cityList['福建']=["福州","厦门","沙县","钓鱼岛","日本岛"];
        cityList['aa']=["xx","zz","vv"];
        cityList['bb']=["xx1","zz2","vv3"];
        cityList['dd']=["11xx","22zz","33vv"];
        cityList['ee']=["xx1122","zz2233","vv4455"];
        var city=document.forms[0].city;
        city.options.length=0;
        var index=document.forms[0].province.value;
        city.options.length=0;
    for(var j in cityList[index]){
        newOption=new Option(cityList[index][j],cityList[index][j]);
        city.options.add(newOption);
    }
    }
</script>
</head>
<body>
<form action="#" method="get">
<select name="country" onchange="change()">
<option value="0" selected="selected">请选择国家</option>
<option value="中国">中国</option>
<option value="美国">美国</option>
<option value="英国">英国</option>
</select>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="province">
<option value="0" selected="selected" onchange="changeCity()">请选择省份</option>
</select>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="city">
<option value="0" selected="selected">请选择城市</option>

</select>
</form>
</body>
</html>
搜索更多相关主题的帖子: javascript change PUBLIC content function javascript function content PUBLIC change 
2014-08-28 13:39
Paxster
Rank: 5Rank: 5
来 自:湖北武汉
等 级:职业侠客
威 望:3
帖 子:40
专家分:320
注 册:2014-7-18
收藏
得分:20 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload=function(){
    var aSelect=document.getElementsByTagName('select')[1];
    var aOption=aSelect.getElementsByTagName('option');
    aSelect.onchange=function(){
        changeCity();
    }
        
};
function change(){
    var provinceList=new Array();
    provinceList['中国']=["浙江","江苏","福建"];
    provinceList['美国']=["aa","bb"];
    provinceList['英国']=["dd","ee"];
    var province=document.forms[0].province;
    province.options.length=0;
    var index=document.forms[0].country.value;
    province.options.length=0;
    for(var j in provinceList[index]){
        newOption=new Option(provinceList[index][j],provinceList[index][j]);
        province.options.add(newOption);
    }
}
function changeCity(){
        var cityList=new Array();
        cityList['浙江']=["杭州","宁波","温州","绍兴","金华","湖州","嘉兴"];
        cityList['江苏']=["南京","苏州","徐州","无锡","常州","镇江"];
        cityList['福建']=["福州","厦门","沙县","钓鱼岛","日本岛"];
        cityList['aa']=["xx","zz","vv"];
        cityList['bb']=["xx1","zz2","vv3"];
        cityList['dd']=["11xx","22zz","33vv"];
        cityList['ee']=["xx1122","zz2233","vv4455"];
        var city=document.forms[0].city;
        city.options.length=0;
        var index=document.forms[0].province.value;
        city.options.length=0;
        for(var j in cityList[index]){
            newOption=new Option(cityList[index][j],cityList[index][j]);
            city.options.add(newOption);
        }
}
</script>
</head>
<body>
<form action="#" method="get">
<select name="country" onchange="change()">
<option value="0" selected="selected">请选择国家</option>
<option value="中国">中国</option>
<option value="美国">美国</option>
<option value="英国">英国</option>
</select>
<select name="province">
<option value="0" selected="selected">请选择省份</option>
</select>
<select name="city">
<option value="0" selected="selected">请选择城市</option>

</select>
</form>
</body>
</html>
------------------------------------------
你的onchange()事件应该绑定给select标签,而不是option标签。

念念不忘,必有回响。
2014-09-04 12:11
快速回复:求大神指点,js 做三级联下拉菜单,第三个下拉菜单没反应额
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036960 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved