zoukankan      html  css  js  c++  java
  • mvc视图双下拉框联动

    html部分的代码

     <tr class="trs">
                    <td class="item1"><div class="item">顶部模块</div></td>
                    <td class="item2">
                        <div class="item">
                            <select style="90%;" id="top">
                                @foreach (var item in ViewBag.device)
                                {
                                <option value="@item.Id" id="@item.Id">@item.Name</option>
                                }
                            </select>
                        </div>
                    </td>
                    <td class="item3">
                        <div class="item">
                            <select style="30%;" id="topitem"></select>
                        </div>
                    </td>
                </tr>

    脚本部分代码

    $(document).ready(function () {
            $("#top").change(function () {
                var top = $("#top").val();
                var topitem = $("#topitem");
                $.ajax({
                    url: "/Site/GetProperty/" + top,
                    type: "post",
                    dataType: "json",
                    contentType: "application/json",
                    success: function (result) {
                        var myHTML = "";
                        topitem.html("");//赋值之前先清空
                        for (var i = 0; i < result.list.length; i++) {
                            myHTML += "<option value=" + result.list[i].id + ">" + result.list[i].name + "</option>";
                        }
                        topitem.append(myHTML);
                    },
                    error: function (result) {
    
                    }
                });
            })
  • 相关阅读:
    ssm框架配置文件
    接口调用post请求参数在body中
    mysql三种连接方式
    jwt认证登录
    JWT工具类
    token的创建及解析
    IIS目录
    C# 增加多个分部类
    计算机知识
    Kibana 的安装(Windows版本)
  • 原文地址:https://www.cnblogs.com/sjrcwy/p/11477409.html
Copyright © 2011-2022 走看看