layui 2.0.x upload additional parameter upload
<div class="layui-inline" style="margin-top: 5px;"> <label class="layui-form-label">机型</label> <div class="layui-input-block"> <input type="radio" name="type" lay-filter="radio-type" value="0" title="andorid" checked> <input type="radio" name="type" lay-filter="radio-type" value="1" title="iOS" > </div> </div> <div class="layui-inline"> <label class="layui-form-label">version description</label> <div class="layui-input-inline"> <input type="text" name="description" id="description" placeholder="请输入" autocomplete="off" class="layui-input"> </div> </div> <div class="layui-inline" > <div class="layui-upload"> <button type="button" class="layui-btn layui-btn-normal" lay-data="{accept: 'file'}" id="test8">选择文件</button> <button type="button" class="layui-btn" lay-data="{accept: 'file'}" id="test9">开始上传</button> </div> </div>
layui.use(['upload','element','form'], function () { var $ = layui.jquery , form = layui.form ,element = layui.element upload = layui.upload; // console.log(_jsonDate) //Do not upload automatically after selecting the file upload.render({ method: 'post' //, data: _jsonDate , item: '# test8' ,exts:'json' ,url: '${ctx}/upload/uploadfile.do' , auto: false //,multiple: true ,bindAction: '#test9' ,before: function(input){ var data = {}; data.type = $('input:radio:checked').val(); data.description = $('#description').val(); this.data=data; } ,done: function(res){ var html = formatJson(JSON.stringify(res)); // console.log(html); $('#show_json').empty(); $('#show_json').html('<pre class="layui-code">' +html+'</pre>'); },success: function(msg){ } }); });
Just add this.data before before (2.0.x)
,before: function(input){ var data = {}; data.type = $('input:radio:checked').val(); data.description = $('#description').val(); this.data=data; }
(1.0.x)
function setdata(input,data){ var item=[]; $.each(data,function(k,v){ item.push('<input type="hidden" name="'+k+'" value="'+v+'">'); }) $(input).after(item.join('')); }
Check layui upload.js has 1.0.x method, 2.0.x is optimized, no need for developers to add input hidden
Donate to developers
Driven by interest, I write 免费
something with joy and sweat. I hope you like my work and can support it at the same time. Of course, if you have money to support a money field (support Alipay, WeChat, and the buckle group), if you have no money to support a personal field, thank you.
Personal homepage : http://knight-black-bob.iteye.com/
Thank you for your sponsorship, I will do better!