layui上传时同时传递Select控件的值的方法

参考:https://jingyan.baidu.com/article/ac6a9a5e7fcf2a6a643eac2b.html

html:

<select id="admin_id">
            <option value="0">请选择业务员</option>
            {foreach $user_list as $key => $v}
            <option value="{$v.id}">{$v.name}</option>
            {/foreach}
        </select>

 

 js:

layui.use('upload', function(){
      var upload = layui.upload;
      // 创建上传接口
      upload.render({
          elem: '#uploadBtn'
          ,url: 'importClient' // 改为你的上传接口URL
          ,accept: 'file' // 允许上传的文件类型
          ,exts: 'xls',
          data: {
                  admin_id:function (){
                      return $("#admin_id").val();
                  }
              }
          ,before: function(){
            // layer.load(); //上传loading
              layer.load(0,{shade: [0.5, '#eee'],time:0,content:'导入中...'});
          }
          ,done: function(res){
              layer.closeAll('loading'); //关闭loading
              // 上传完毕回调
              if(res.code == 200){
                  var str = '导入成功:'+res.success_num+"条,"+"失败:"+res.fail_num+"";
                  $("#msg").css("color","green");
                  $("#msg").text(str);
              }else{
                  $("#msg").css("color","red");
                  $("#msg").text(res.msg);
              }
              console.log(res);
          },error:function (){
              layer.closeAll('loading'); //关闭loading
          }
      });
  });

 

posted @ 2024-11-25 14:50  流浪2024  阅读(6)  评论(0编辑  收藏  举报