zoukankan      html  css  js  c++  java
  • select下拉的绑定及回显(ajxa)

    下拉列表一般通过ajax请求数据绑定

    // 绑定新闻类型下拉
    function news_type() {
        var news_type=$("#news_type").val();
        $(".remove").remove();
        $.ajax({
            url : path + "/base/newsType",
            type : "POST",
            data : "json",
            success : function(data) {
                var html = '';
                for (var i = 0; i < data.length; i++) {
                    var checked="";
                    //如果id等于value,则选中
                    if(data[i].id==news_type){
                        checked="selected="selected"";
                    }
                    html += "  <option "+checked+" class='remove' value='" + data[i].id + "'>"
                            + data[i].name + "</option>";
                }
                $(".news_type").append(html);
    
            },
            erro : function(e) {
                $.messager.alert("提示", "错误!", "error");
            }
        });
    }

    前端代码

    <select class='news_type'></select>

    后台返回的是List集合

  • 相关阅读:
    mybatis
    spring mvc
    Spring Boot2
    Spring AOP
    Spring Boot1
    Spring IOC
    Multiple_LinearRegression_Test2
    Multiple_LinearRegression_Test
    Simple_LinearRegression_Test
    写决策树时遇到的坑
  • 原文地址:https://www.cnblogs.com/angto64/p/5253547.html
Copyright © 2011-2022 走看看