thinkphp3.1 二级联动菜单

2018-05-25  本文已影响0人  cuihaomaster

部门和责任人联动

ajax交互:点击获取部门id,传给后端,后端根据id查到数据,return,js再给select赋值

                        <select name="bm" id="bm">
                           <volist name="branch" id="vo">
                               <option value="{$vo.b_id}">{$vo.branch_name}</option>
                           </volist>
                       </select>

                      <select name="zrr" id="zrr">
                          <volist name="fusers" id="vo">
                              <option value="{$vo.user_nicename}">{$vo.user_nicename}</option>
                          </volist>
                      </select>

              <!--部门和责任人联动-->
              <script>
                  $('#bm').click(function(){
                          $(this).change(function(){
                              var bm_id = $(this).val();//获取选择的部门的id
                              console.log(bm_id);

                              $.ajax({
                                  cache:false,
                                  type:"POST",
                                  url:"{:u('Taiz/ld')}",
                                  dataType:"json",
                                  data:{"bm_id":bm_id},
                                  success:function(zrr){
                                      //console.log(zrr['Object']);

                                      var html="";
                                      $("#zrr").empty();
                                      $.each(zrr,function(k,v){
                                          //console.log(v);
                                          if(v.user_nicename !== undefined){
                                              html += "<option value="+v.user_nicename+">"+v.user_nicename+"</option>";
                                          }

                                      })
                                      $("#zrr").append(html);
                                  }
                              });
                          });
                      }
                  );
              </script>
上一篇下一篇

猜你喜欢

热点阅读