bootstrap-select2 ajax初始化显示数据 赋值 取值

赋值

$.ajax({
            type: 'get',
            url: testPath +'/api/dict/data/certificates/type',
            dataType: "json",
            contentType: "application/json",
            headers:{'token':token,orign:'web',Accept: "application/json; charset=utf-8"},
            success: function (data) {
                if(data.code==200 || data.code=='200'){
                    console.log(data);
                    var typeList = data.data;
                    var typeListHtml = '';
                    $.each(typeList,function(idx,item){
                        typeListHtml += '<option value = '+item.value +'>'+ item.desc +'</option>'
                    });
                    $('#dlrCardType').html(typeListHtml).select2();
                    $('#dsrCardType').html(typeListHtml).select2();
                    //赋值
                    $("#dlrCardType").val(typeList[0].value).select2();
                    $("#dsrCardType").val(typeList[0].value).select2();
                }
                else{
                    layer.msg(data.msg);
                }

            }
        })

取值

$("#dsrCardType").val();

猜你喜欢

转载自www.cnblogs.com/hukeer/p/12552555.html
今日推荐