select在项目中的总结(select的状态改变;selsec的二级联动)

ajax请求传参:

var stat0,stat1;
if(data.data[i].STAT==0){
   stat0 ='selected=selected';
   stat1 ='';
 }else{
   stat1 ='selected=selected';
   stat0 ='';
};

"<td>"+
  "<select name='' autocomplete='off' id='states' style='border:none; outline:none;color: #00a09e;' onchange='ststeCall("+data.data[i].FACID+",this,0)'>"+
    "<option value='0' "+stat0+">有效</option>"+
    "<option value='1' "+stat1+">无效</option>"+
  "</select>"+
"</td>" +

//状态
function ststeCall(id,tis,flg){
  var num=$(tis).val(); //0或1
  //掉接口给后端传值,改变状态
}

 

 

select的二级联动:

html:

<select class='scheduli schedu_department' id="liandorgname">
  <!-- <option value ='0'>选择科室</option>
  <option value='1'>内科</option> -->    
</select>

<select class='scheduli schedu_doctor' id="lianddoctor">
  <option value ='-1'>选择医生</option>
  <!-- <option value='1'>周</option> -->    
</select>

 

js:

$(function(){
//科室类型传参获取所有科室
selectAdd("科室类型",function(data){
  $("#liandorgname").html("");
  $("#liandorgname").append("<option value='-1'>请选择科室</option>");
  for (var i = 0; i < data.length; i++) {
    $("#liandorgname").append("<option value='"+data[i].dictId+"'>"+data[i].dictName+"</option>");
  }
})
function selectAdd(name,initSelectfun){
   $.ajax({
     url:"/doctormanage/dict/getdict.do",
     type:"post",
     dataType:"json",
     data:{
       "name":name
     },success:function(data){
       initSelectfun(data.data);
     }
   });
}
//一级change改变获取科室id
$("#liandorgname").on('change',function () { 
  var orgId = $(this).val();
  $('#lianddoctor').val('').trigger('change'); 
  dataAllname(orgId,function(data){
    $("#lianddoctor").html("");
    $("#lianddoctor").append("<option value='-1'>请选择医生</option>");
    for (var i = 0; i < data.length; i++) {
      $("#lianddoctor").append("<option value='"+data[i].id+"'>"+data[i].doctorName+"</option>");
    }
  });
});
//二级联动 传科室Id 获取医生列表
function dataAllname(orgId,initSelectfun){
  var datas;
  $.ajax({
    url:"/doctormanage/user/getuserbyname.do",
    type:"post",
    dataType:"json",
    data:{
      "name":"",
      "orgId":orgId,
      "date":""
    },success:function(data){
      console.log(data)
      initSelectfun(data.data);
    }
  });
  return datas;
}    
})

 

posted @ 2018-08-03 15:13  小凢  阅读(241)  评论(0编辑  收藏  举报