html之二级联动


<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Documenttitle>
    <script>
        var proData = {"河北省":["网吧","大姐"],"河男省":["市北","石楠"],"河西省":["大唐","满清"],"河东省":["母鸡","公鸡"]};
        window.onload = function () {
            var oSelectPro = document.getElementById('pro_id');
            var oSelectCity = document.getElementById('city_id');

            oSelectPro.onchange = function () {
                //获取当前选中的标签值
                var aRrayCity = proData[this.value];
                //选择后清空option
                oSelectCity.options.length=0;
                for (var i=0;ivar oOption = document.createElement('option');
                    oOption.innerHTML = aRrayCity[i];
                    oOption.value = aRrayCity[i];
                    oSelectCity.appendChild(oOption)
                }
//                for (this.value in proData){
//                    alert(proData[this.value])
//                }
            }
        }
    script>

head>
<body>
    <select name="province" id="pro_id">
        <option value="河北省">河北省option>
        <option value="河男省">河男省option>
        <option value="河西省">河西省option>
        <option value="河东省">河东省option>
    select>

    <select name="city" id="city_id">

    select>

body>
html>

你可能感兴趣的:(HTML)