JS 城市联动

<select name="" id="province">
    <option value="0">北京</option>        
    <option value="1">河南</option>        
    <option value="2">河北</option>        
    <option value="3">陕西</option>        
</select>
<select name="" id="city">
    <option value="0">请选择</option>
</select>
<script type="text/javascript">
    var city = [];
    city[0] = ['东城区','西城区','朝阳区','昌平区'];
    city[1] = ['郑州','安阳','商丘','信阳'];
    city[2] = ['石家庄', '唐山','保定','承德'];
    city[3] = ['西安','宝鸡','安康','商洛'];

    //绑定事件
    var prov = document.getElementById('province');
    var citys = document.getElementById('city');

    prov.onchange = function() {
        //获取当前省下面的市.
        var v = this.value;//这是获取当前正在选中的option元素的值
        var cs = city[v];
        //拼接字符串设置文本
        var str = '';
        for(var i=0;i<cs.length;i++) {
            str += '<option value="'+i+'">'+cs[i]+'</option>';
        }
        // console.log(str);
        citys.innerHTML = str;
    }
</script>