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();

select2在彈出框不顯示的問題

var caseYearList = data.data;
                                var caseYearHtml = '';
                                $.each(caseYearList,function(idx,item){
                                    caseYearHtml += '<option value = '+item +'>'+ item +'</option>'
                                });
                                $('#caseYear').html(caseYearHtml).select2({dropdownParent: $('#importNotarialBook'),width:'300px'});//select2在彈出框不顯示的問題


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM