bootstrap-select标签 在做回显选中的时候

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/WO8451401/article/details/79280951

在添加数据的时候,其中传参方式,在拼接之后它自带一些样式,下拉状态想要获取选中的value值 可以通过下面方法

function getSelectedVal(id){
   var html = $('button[data-id='+id+'] span.filter-option').html();
   if(!html) return;
   var arr = html.split(', ');
   var str = '';
   $.each($('#'+id+' option'),function(k,v){
      $.each(arr,function(m,n){
         if(n==$(v).html()) str+=($(v).val()+';');
      })
   });
   str = str.substring(0,str.length-1);
   return str;
}

只需要传递select标签中的id值 便可以获取到选中的val()。

在回显的时候需要先拿到状态之前的值,然后遍历比对,赋selected属性  如下

function checkBoxTradeType() {
   $("#checkBoxTradeType").empty();
   var checkBoxTradeType="";
   var flag = false;
   var tradeType = $("#tradeType").val();
   console.log(tradeType);
   var strs= new Array();
   strs= tradeType.split(";");
   $.ajax({
        url: contextPath +'/getLookupCdeList.jhtml?r='+Math.random(),
         async:false ,
         cache:true,
        type:"POST",
        data:{
           "typeCode":"10311001"
               },
        success: function(result) {
           result.sort(function(a,b){
              return a.integerKey-b.integerKey;
           });
           $.each(result, function(k, v) {
              for (var int = 0; int < strs.length; int++) {
               if(strs[int] == v.id){
                  flag = true;
               }
              }
              if(flag){
                  checkBoxTradeType=checkBoxTradeType+'<option class="" selected value="'+v.id+'" id="'+v.id+'">'+v.cdeName+'</option>';

              }else{
                  checkBoxTradeType=checkBoxTradeType+'<option class="" value="'+v.id+'" id="'+v.id+'">'+v.cdeName+'</option>';
              }
              flag = false;
           });
        }
      });
   $("#checkBoxTradeType").html(checkBoxTradeType);
}





猜你喜欢

转载自blog.csdn.net/WO8451401/article/details/79280951
今日推荐