html의 2단계 연동

5581 단어 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>

좋은 웹페이지 즐겨찾기