本文实例为大家分享了layui文件上传的具体代码,供大家参考,具体内容如下
<Meta charset="UTF-8">
文件上传
<input type="file" name="file" class="layui-upload-file">
<input type="file" name="file1" lay-type="file" class="layui-upload-file">
<input type="file" name="file1" lay-type="au<a href="/tag/dio/" target="_blank" class="keywords">dio</a>" class="layui-upload-file">
<input type="file" name="file2" lay-type="video" class="layui-upload-file">
<blockquote class="layui-elem-quote" style="margin-top: 20px;"><a href="/tag/zhichi/" target="_blank" class="keywords">支持</a>拖动<a href="/tag/wenjian/" target="_blank" class="keywords">文件</a><a href="/tag/shangchuan/" target="_blank" class="keywords">上传</a></blockquote>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
<legend>演示<a href="/tag/shangchuan/" target="_blank" class="keywords">上传</a></legend>
</fieldset>
<div class="site-demo-upload">
<img id="LAY_demo_upload" src="layui/images/tong.jpg">
<div class="site-demo-upbar">
<input type="file" name="file" class="layui-upload-file" id="test">
</div>
</div>
<p style="margin-top: 20px;">注:由于服务器资源有限,所以此处每次给你返回的是同一张<a href="/tag/tupian/" target="_blank" class="keywords">图片</a></p>
<script src="layui/layui.js"></script>
<script>
layui.use('upload',function(){
layui.upload({
url: '' //<a href="/tag/shangchuan/" target="_blank" class="keywords">上传</a>接口,success: function(res){ //<a href="/tag/shangchuan/" target="_blank" class="keywords">上传</a>成功后的回调
console.log(res)
}
});
layui.upload({
url: '/test/upload.json',elem: '#test' //指定原始元素,默认直接查找class="layui-upload-file",method: 'get' //<a href="/tag/shangchuan/" target="_blank" class="keywords">上传</a>接口的http类型,success: function(res){
LAY_demo_upload.src = res.url;
}
});
});
</script>