javascript - 我的联动怎么就没效果呢?
伊谢尔伦
伊谢尔伦 2017-04-10 16:36:08
0
1
127

<!DOCUMENT>

<head>

<script>
    function lian() {
        var level = new Array("一线城市", "二线城市", "三线城市");
        var one = document.getElementById("s1");
        for (i = 0; i < 3; i++) {
            var opt = document.createElement("option");
            opt.value = i;
            opt.innerText = level[i];
            one.appendChild(opt);
        }

    }

    function changeValue() {
        var one = document.getElementById("s1");
        var two = document.getElementById("s2");
        var a = new Array("北京", "上海", "广州");
        var b = new Array("南京", "深圳", "长沙");
        var c = new Array("常德", "益阳", "衡阳");
        var sel = one.value;
        if (sel == 2) {
            for (i = 0; i < 3; i++) {
                var opt_1 = document.createElement("opiton");
                opt_1.value = i;
                opt_1.innerText = a[i];
                two.appendChild(opt_1);
            }
        }
    if (sel == 1) {
        for (i = 0; i < 3; i++) {
            var opt_1 = document.createElement("opiton");
            opt_1.value = i;
            opt_1.innerText = b[i];
            two.appendChild(opt_1);
        }
    }
    if (sel == 0) {
        for (i = 0; i < 3; i++) {
            var opt_1 = document.createElement("opiton");
            opt_1.value = i;
            opt_1.innerText = c[i];
            two.appendChild(opt_1);
        }
    }
    }
</script>

</head>
<html>

<body onload="lian()">

<select id="s1" onchange="changeValue()">
</select>

<select id="s2">
</select>

</body>

</html>

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(1)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!