首页 > 其他 > 详细

省市级联操作

时间:2014-08-19 18:27:25      阅读:258      评论:0      收藏:0      [点我收藏+]

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>省市级联操作</title>
<script type="text/javascript">
    var provinces = new Array(
        new Array("00","--选择省份--"),
        new Array("01","北京市"),
        new Array("02","湖北省"),
        new Array("03","河南省"),
        new Array("04","河北省"),
        new Array("05","江苏省")
    );
    var citys = new Array(
        new Array("0101","北京市"),
        new Array("0102","通州"),
        new Array("0103","五环"),
        new Array("0201","武汉"),
        new Array("0202","武汉"),
        new Array("0203","武汉"),
        new Array("0301","郑州"),
        new Array("0302","郑州"),
        new Array("0303","郑州"),
        new Array("0401","石家庄"),
        new Array("0402","石家庄"),
        new Array("0403","石家庄"),
        new Array("0501","南京"),
        new Array("0502","苏州"),
        new Array("0503","常州")
    );
    function fillprovince(){
        var province = document.getElementById("province");
        for(var i = 0;i<provinces.length;i++){
            var option = new Option(provinces[i][1],provinces[i][0]);
            province.add(option);
        }
    }
    function changeCity(){
        var province = document.getElementById("province");
        var procode = province.options[province.selectedIndex].value;
        var city = document.getElementById("city");
        city.options.length = 0;
        for(var i = 0;i<citys.length;i++){
            if(citys[i][0].substring(0,2)==procode){
                city.options.add(new Option(citys[i][1],citys[i][0]));
            }
        }
    }
</script>
</head>
<body>
<select id="province" onchange="changeCity()">
<script type="text/javascript">fillprovince();</script>
</select>
<select id="city" style="width: 100px"></select>
</body>
</html>

省市级联操作,布布扣,bubuko.com

省市级联操作

原文:http://www.cnblogs.com/siashan/p/3922496.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!