HTML:
<label for="InputFile" class="col-lg-4 col-sm-4 col-xs-4"><span class="text-red">*</span>图片:</label>
<div class="col-lg-16 col-sm-16 col-xs-16">
<input type="file" id="InputFile" name="InputFile" value="{{url}}" accept="image/gif,image/jpeg,image/jpg,image/png,image/svg">
<input type="hidden" name="url" value="{{url}}">
</div>
JS:
var $file = $page.find('.T-basicInfo-main [name="imgUrl"]'); $page.find('.T-basicInfo-main').on('change', '[name="InputFile"]', function () { var $that = $(this), args = {}; if(!$that.val()) { $file.val(''); return false; } var picData = new FormData(); picData.append('file', $that[0].files[0]); Services.ajax({ url: '/picture/picture.do', method: 'uploadFile', processData: 'false', type: 'POST', async: 'false', contentType: 'false', args: picData, done: function(res) { $file.val(res.data.map.url); } }); });
Services.ajax为封装的ajax,可以直接使用jq的ajax;