MVC省市二级联动

<script>
        $(function () {
            ShowSheng();
        })
        function ShowSheng() {
            $.ajax({
                url: "/Home/Sheng",
                type: "get",
                dataType: "json",
                success: function (da) {
                    $(da).each(function (index, item) {
                        $("#S1").append("<option value='" + item.Aid + "'>" + item.Aname + "</option>");
                    })
                }
            })
        }
        function SelQu(t) {
            var m = $(t).val();
            $.ajax({
                url: "/Home/Shi",
                type: "get",
                data: { id: m },
                dataType: "json",
                success: function (da) {
                    $("#S2").empty();
                    $(da).each(function (index, item) {
                        $("#S2").append("<option value='" + item.Aid + "'>" + item.Aname + "</option>");
                    })
                }
            })
        }
    </script>
 
<div>
省市:<select id="S1" onchange="SelQu(this)"><option value="0">---请选择省市---</option></select>区镇:<select id="S2"><option value="0">---请选择区镇---</option></select>
</div>
posted @ 2018-11-22 10:32  或三撇  阅读(396)  评论(0)    收藏  举报