HTML code
<form class="layui-form"> <div class="layui-form-item"> <label class="layui-form-label">Tail light name</label> <div class="layui-input-block"> <input type="text" name="name" required lay-verify="required" placeholder="Please enter the taillight name" class="layui-input"> </div> </div> <div class="layui-form-item"> <div class="layui-input-block"> <button type="button" class="layui-btn" > <i class="layui-icon">&#xe67c;</i>Upload icon </button> <br><br> <div style="width:200px;height:200px;border:3px solid #0099CC;border-radius: 5px;padding: 3px;"> <img style="max-width: 200px;max-height:200px;" > </div> </div> </div> <div class="layui-form-item"> <div class="layui-input-block"> <button class="layui-btn" onclick="return false">Submit now</button> </div> </div> </form>
JavaScript Code
<script> (['form', 'layer', 'upload'], function () { var layer = ; var upload = ; var $ = ; ({ elem: '#upload', url: '{:U("addTL")}', auto: false,//Not uploading automatically after selecting a file bindAction: '#commit', //Callback before upload before: function () { = { name: $('input[name="name"]').val() } }, //Callback after selecting file choose: function (obj) { (function (index, file, result) { $('#preview').attr('src', result); }) }, //A callback with successful operation done: function (res, index, upload) { var code = === 0 ? 1 : 2; (, {icon: code}, function () { (); }) }, //Upload error callback error: function (index, upload) { ('Upload failed! ' + index); } }); }) </script>
The above example of uploading forms and files to the background is all the content I share with you. I hope you can give you a reference and I hope you support me more.