<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>文件上传</title> <link href="https://www.jb51.net/layui/css/layui.css"> <link href="https://www.jb51.net/css/global.css"> </head> <body> <fieldset> <legend>设定上传文件的格式</legend> </fieldset> <input type="file"> <input type="file" lay-type="file"> <input type="file" lay-type="audio"> <input type="file" lay-type="video"> <blockquote>支持拖动文件上传</blockquote> <fieldset> <legend>演示上传</legend> </fieldset> <div> <img src="https://www.jb51.net/layui/images/tong.jpg"> <div> <input type="file"> </div> </div> <p>注:由于服务器资源有限,所以此处每次给你返回的是同一张图片</p> <script src="https://www.jb51.net/layui/layui.js"></script> <script> layui.use('upload', function(){ layui.upload({ url: '' //上传接口 ,success: function(res){ //上传成功后的回调 console.log(res) } }); layui.upload({ url: '/test/upload.json' ,elem: '#test' //指定原始元素,默认直接查找class="layui-upload-file" ,method: 'get' //上传接口的http类型 ,success: function(res){ LAY_demo_upload.src = res.url; } }); }); </script> </body> </html>
官网文件上传