Home > Web Front-end > JS Tutorial > layui file upload to realize code sharing

layui file upload to realize code sharing

小云云
Release: 2018-05-11 11:02:28
Original
4036 people have browsed it

This article mainly introduces the implementation code of layui navigation bar effect in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>文件上传</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/global.css">
  </head>
  <body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
      <legend>设定上传文件的格式</legend>
    </fieldset>

    <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="audio" 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;">支持拖动文件上传</blockquote>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
      <legend>演示上传</legend>
    </fieldset>
    <p class="site-demo-upload">
      <img id="LAY_demo_upload" src="layui/images/tong.jpg">
      <p class="site-demo-upbar">
        <input type="file" name="file" class="layui-upload-file" id="test">
      </p>
    </p>

    <p style="margin-top: 20px;">注:由于服务器资源有限,所以此处每次给你返回的是同一张图片</p>

    <script src="layui/layui.js"></script>
    <script>
      layui.use(&#39;upload&#39;, function(){
        layui.upload({
        url: &#39;&#39; //上传接口
        ,success: function(res){ //上传成功后的回调
          console.log(res)
         }
      });

      layui.upload({
        url: &#39;/test/upload.json&#39;
        ,elem: &#39;#test&#39; //指定原始元素,默认直接查找class="layui-upload-file"
        ,method: &#39;get&#39; //上传接口的http类型
        ,success: function(res){
          LAY_demo_upload.src = res.url;
        }
      });

      });
    </script>
  </body>
</html>
Copy after login

Official website file upload

Related recommendations:

jquery implements secondary linkage drop-down selection based on layui

Share how LayUI implements the front-end paging function

Detailed explanation of how layui.js implements the form verification function

The above is the detailed content of layui file upload to realize code sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template